lib: Define and use cleanup functions for gpgme

Just a cleanup in preparation for future work.

Closes: #575
Approved by: giuseppe
This commit is contained in:
Colin Walters 2016-11-16 09:19:52 -05:00 committed by Atomic Bot
parent bd45e7ac19
commit a6cfe62eb8
3 changed files with 12 additions and 23 deletions

View File

@ -25,6 +25,7 @@
#include "libglnx.h"
#include "ostree-gpg-verifier.h"
#include "ot-gpg-utils.h"
#include "ostree-gpg-verify-result-private.h"
#include "otutil.h"
@ -89,10 +90,9 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier *self,
GCancellable *cancellable,
GError **error)
{
gpgme_ctx_t gpg_ctx = NULL;
gpgme_error_t gpg_error = 0;
gpgme_data_t data_buffer = NULL;
gpgme_data_t signature_buffer = NULL;
ot_auto_gpgme_data gpgme_data_t data_buffer = NULL;
ot_auto_gpgme_data gpgme_data_t signature_buffer = NULL;
g_autofree char *tmp_dir = NULL;
g_autoptr(GOutputStream) target_stream = NULL;
OstreeGpgVerifyResult *result = NULL;
@ -191,14 +191,6 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier *self,
success = TRUE;
out:
if (gpg_ctx != NULL)
gpgme_release (gpg_ctx);
if (data_buffer != NULL)
gpgme_data_release (data_buffer);
if (signature_buffer != NULL)
gpgme_data_release (signature_buffer);
if (success)
{
/* Keep the temporary directory around for the life of the result

View File

@ -1440,9 +1440,9 @@ ostree_repo_remote_gpg_import (OstreeRepo *self,
GError **error)
{
OstreeRemote *remote;
gpgme_ctx_t source_context = NULL;
gpgme_ctx_t target_context = NULL;
gpgme_data_t data_buffer = NULL;
ot_auto_gpgme_ctx gpgme_ctx_t source_context = NULL;
ot_auto_gpgme_ctx gpgme_ctx_t target_context = NULL;
ot_auto_gpgme_data gpgme_data_t data_buffer = NULL;
gpgme_import_result_t import_result;
gpgme_import_status_t import_status;
const char *tmp_dir = NULL;
@ -1700,15 +1700,6 @@ out:
if (target_tmp_dir != NULL)
(void) glnx_shutil_rm_rf_at (AT_FDCWD, target_tmp_dir, NULL, NULL);
if (source_context != NULL)
gpgme_release (source_context);
if (target_context != NULL)
gpgme_release (target_context);
if (data_buffer != NULL)
gpgme_data_release (data_buffer);
g_prefix_error (error, "GPG: ");
return ret;

View File

@ -22,9 +22,15 @@
#include <gpgme.h>
#include <gio/gio.h>
#include "libglnx.h"
G_BEGIN_DECLS
GLNX_DEFINE_CLEANUP_FUNCTION0(gpgme_data_t, ot_cleanup_gpgme_data, gpgme_data_release)
#define ot_auto_gpgme_data __attribute__((cleanup(ot_cleanup_gpgme_data)))
GLNX_DEFINE_CLEANUP_FUNCTION0(gpgme_ctx_t, ot_cleanup_gpgme_ctx, gpgme_release)
#define ot_auto_gpgme_ctx __attribute__((cleanup(ot_cleanup_gpgme_ctx)))
void ot_gpgme_error_to_gio_error (gpgme_error_t gpg_error, GError **error);
gboolean ot_gpgme_ctx_tmp_home_dir (gpgme_ctx_t gpgme_ctx,