From: Andrej Kacian Date: Tue, 11 Jul 2017 19:09:24 +0000 (+0200) Subject: Fix a few memory leaks when enumerating keys with GpgME. X-Git-Tag: 3.16.0~108 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=11980bc7a384136cc2d9aada20988bcd462b1ffc Fix a few memory leaks when enumerating keys with GpgME. Also replaced uses of deprecated gpgme_key_release() with gpgme_key_unref(). --- diff --git a/src/plugins/pgpcore/autocompletion.c b/src/plugins/pgpcore/autocompletion.c index 286f24194..a4f15a6b1 100644 --- a/src/plugins/pgpcore/autocompletion.c +++ b/src/plugins/pgpcore/autocompletion.c @@ -100,7 +100,7 @@ static gboolean pgp_autocompletion_hook(gpointer source, gpointer data) i++; } } - gpgme_key_release(key); + gpgme_key_unref(key); } gpgme_release(ctx); } diff --git a/src/plugins/pgpcore/select-keys.c b/src/plugins/pgpcore/select-keys.c index 69a7f8af9..47e4b66fd 100644 --- a/src/plugins/pgpcore/select-keys.c +++ b/src/plugins/pgpcore/select-keys.c @@ -167,7 +167,7 @@ static void destroy_key (gpointer data) { gpgme_key_t key = data; - gpgme_key_release (key); + gpgme_key_unref (key); } static void @@ -320,6 +320,8 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot g_free(raw_mail); } num_results++; + if (last_key != NULL) + gpgme_key_unref(last_key); last_key = key; key = NULL; update_progress (sk, ++running, pattern); @@ -344,7 +346,11 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot gpgme_release (ctx); } /*gtk_cmclist_thaw (select_keys.clist);*/ - return (exact_match == TRUE && num_results == 1 ? last_key:NULL); + if (exact_match && num_results == 1) + return last_key; + + gpgme_key_unref(last_key); + return NULL; } diff --git a/src/plugins/pgpcore/sgpgme.c b/src/plugins/pgpcore/sgpgme.c index 2290526a7..0579f4205 100644 --- a/src/plugins/pgpcore/sgpgme.c +++ b/src/plugins/pgpcore/sgpgme.c @@ -607,37 +607,43 @@ gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account, /* Look for any key, not just private ones, or GPGMe doesn't * correctly set the revoked flag. */ err = gpgme_op_keylist_start(ctx, keyid, 0); - while ((err = gpgme_op_keylist_next(ctx, &key)) == 0) { + while (err == 0) { + if ((err = gpgme_op_keylist_next(ctx, &key)) != 0) + break; + if (key == NULL) continue; - if (!key->can_sign) + if (!key->can_sign) { + debug_print("skipping a key, can not be used for signing\n"); + gpgme_key_unref(key); continue; + } if (key->protocol != gpgme_get_protocol(ctx)) { debug_print("skipping a key (wrong protocol %d)\n", key->protocol); - gpgme_key_release(key); + gpgme_key_unref(key); continue; } if (key->expired) { debug_print("skipping a key, expired\n"); - gpgme_key_release(key); + gpgme_key_unref(key); continue; } if (key->revoked) { debug_print("skipping a key, revoked\n"); - gpgme_key_release(key); + gpgme_key_unref(key); continue; } if (key->disabled) { debug_print("skipping a key, disabled\n"); - gpgme_key_release(key); + gpgme_key_unref(key); continue; } if (found_key != NULL) { - gpgme_key_release(key); + gpgme_key_unref(key); gpgme_op_keylist_end(ctx); g_warning("ambiguous specification of secret key '%s'", keyid); privacy_set_error(_("Secret key specification is ambiguous")); @@ -645,7 +651,7 @@ gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account, } found_key = key; - } + } gpgme_op_keylist_end(ctx); if (found_key == NULL) { @@ -658,7 +664,7 @@ gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account, debug_print("got key (proto %d (pgp %d, smime %d).\n", found_key->protocol, GPGME_PROTOCOL_OpenPGP, GPGME_PROTOCOL_CMS); - gpgme_key_release(found_key); + gpgme_key_unref(found_key); if (err) { g_warning("error adding secret key: %s", @@ -1094,6 +1100,7 @@ check_again: err = gpgme_op_keylist_start(ctx, NULL, TRUE); if (!err) err = gpgme_op_keylist_next(ctx, &key); + gpgme_key_unref(key); /* We're not interested in the key itself. */ gpgme_op_keylist_end(ctx); if (gpg_err_code(err) == GPG_ERR_EOF) { if (gpgme_get_protocol(ctx) != GPGME_PROTOCOL_CMS) {