lib: Define and use an autoptr cleanup for gpgme_key_t

Followup for previous patch, allows porting a bit to new code style.

Closes: #1039
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-07-31 11:31:13 -04:00 committed by Atomic Bot
parent b929b620ae
commit d3897e52e7
2 changed files with 7 additions and 15 deletions

View File

@ -237,10 +237,9 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
const gchar *key_id,
guint *out_signature_index)
{
gpgme_key_t lookup_key = NULL;
g_auto(gpgme_key_t) lookup_key = NULL;
gpgme_signature_t signature;
guint signature_index;
gboolean ret = FALSE;
g_return_val_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result), FALSE);
g_return_val_if_fail (key_id != NULL, FALSE);
@ -258,7 +257,7 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
signature != NULL;
signature = signature->next, signature_index++)
{
gpgme_key_t signature_key = NULL;
g_auto(gpgme_key_t) signature_key = NULL;
(void) gpgme_get_key (result->context, signature->fpr, &signature_key, 0);
@ -274,18 +273,13 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
{
if (out_signature_index != NULL)
*out_signature_index = signature_index;
ret = TRUE;
/* Note early return */
return TRUE;
}
gpgme_key_unref (signature_key);
if (ret)
break;
}
gpgme_key_unref (lookup_key);
return ret;
return FALSE;
}
/**
@ -312,7 +306,7 @@ ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
guint n_attrs)
{
GVariantBuilder builder;
gpgme_key_t key = NULL;
g_auto(gpgme_key_t) key = NULL;
gpgme_signature_t signature;
guint ii;
@ -433,9 +427,6 @@ ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
g_variant_builder_add_value (&builder, child);
}
if (key != NULL)
gpgme_key_unref (key);
return g_variant_builder_end (&builder);
}

View File

@ -28,6 +28,7 @@ G_BEGIN_DECLS
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(gpgme_data_t, gpgme_data_release, NULL);
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(gpgme_ctx_t, gpgme_release, NULL);
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(gpgme_key_t, gpgme_key_unref, NULL)
void ot_gpgme_error_to_gio_error (gpgme_error_t gpg_error, GError **error);