json: Fix minor memory leaks.

* src/gpgme-json.c (interactive_repl): Fix memleak.
(subkey_to_json): Ditto
(op_config): Delay init of j_comps to avoid a leak on error.
--

GnuPG-bug-id: 4341, 4342, 4343
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-01-25 13:31:47 +01:00
parent 66bcb8acb2
commit 7f24233719
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -1003,6 +1003,7 @@ static cjson_t
subkey_to_json (gpgme_subkey_t sub) subkey_to_json (gpgme_subkey_t sub)
{ {
cjson_t result = xjson_CreateObject (); cjson_t result = xjson_CreateObject ();
char *tmp;
xjson_AddBoolToObject (result, "revoked", sub->revoked); xjson_AddBoolToObject (result, "revoked", sub->revoked);
xjson_AddBoolToObject (result, "expired", sub->expired); xjson_AddBoolToObject (result, "expired", sub->expired);
@ -1016,11 +1017,13 @@ subkey_to_json (gpgme_subkey_t sub)
xjson_AddBoolToObject (result, "is_qualified", sub->is_qualified); xjson_AddBoolToObject (result, "is_qualified", sub->is_qualified);
xjson_AddBoolToObject (result, "is_cardkey", sub->is_cardkey); xjson_AddBoolToObject (result, "is_cardkey", sub->is_cardkey);
xjson_AddBoolToObject (result, "is_de_vs", sub->is_de_vs); xjson_AddBoolToObject (result, "is_de_vs", sub->is_de_vs);
xjson_AddStringToObject0 (result, "pubkey_algo_name", xjson_AddStringToObject0 (result, "pubkey_algo_name",
gpgme_pubkey_algo_name (sub->pubkey_algo)); gpgme_pubkey_algo_name (sub->pubkey_algo));
xjson_AddStringToObject0 (result, "pubkey_algo_string",
gpgme_pubkey_algo_string (sub)); tmp = gpgme_pubkey_algo_string (sub);
xjson_AddStringToObject0 (result, "pubkey_algo_string", tmp);
xfree (tmp);
xjson_AddStringToObject0 (result, "keyid", sub->keyid); xjson_AddStringToObject0 (result, "keyid", sub->keyid);
xjson_AddStringToObject0 (result, "card_number", sub->card_number); xjson_AddStringToObject0 (result, "card_number", sub->card_number);
xjson_AddStringToObject0 (result, "curve", sub->curve); xjson_AddStringToObject0 (result, "curve", sub->curve);
@ -2925,7 +2928,7 @@ op_config (cjson_t request, cjson_t result)
gpgme_conf_comp_t comp = NULL; gpgme_conf_comp_t comp = NULL;
cjson_t j_tmp; cjson_t j_tmp;
char *comp_name = NULL; char *comp_name = NULL;
cjson_t j_comps = xjson_CreateArray (); cjson_t j_comps;
ctx = get_context (GPGME_PROTOCOL_GPGCONF); ctx = get_context (GPGME_PROTOCOL_GPGCONF);
@ -2947,6 +2950,7 @@ op_config (cjson_t request, cjson_t result)
goto leave; goto leave;
} }
j_comps = xjson_CreateArray ();
comp = conf; comp = conf;
for (comp = conf; comp; comp = comp->next) for (comp = conf; comp; comp = comp->next)
{ {
@ -3563,7 +3567,11 @@ interactive_repl (void)
if (!request) if (!request)
request = xstrdup (line); request = xstrdup (line);
else else
request = xstrconcat (request, "\n", line, NULL); {
char *tmp = xstrconcat (request, "\n", line, NULL);
xfree (request);
request = tmp;
}
} }
if (!line) if (!line)