From 51fd6d8292cb41d743407e6ac9d86a5ab8e68d8c Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 6 Feb 2013 17:35:40 +0100 Subject: Use gpg_error_from_syserror instead of directly accessing errno. -- Also fixed a couple of minor thing; e.g. save the error before calling cleanup functions. Do not save the errno if only free is called in between. --- src/gpgme.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/gpgme.c') diff --git a/src/gpgme.c b/src/gpgme.c index 2c6ac875..86099d60 100644 --- a/src/gpgme.c +++ b/src/gpgme.c @@ -87,7 +87,7 @@ gpgme_new (gpgme_ctx_t *r_ctx) ctx = calloc (1, sizeof *ctx); if (!ctx) - return TRACE_ERR (gpg_error_from_errno (errno)); + return TRACE_ERR (gpg_error_from_syserror ()); INIT_LOCK (ctx->lock); @@ -95,7 +95,7 @@ gpgme_new (gpgme_ctx_t *r_ctx) if (!ctx->engine_info) { free (ctx); - return TRACE_ERR (gpg_error_from_errno (errno)); + return TRACE_ERR (gpg_error_from_syserror ()); } ctx->keylist_mode = GPGME_KEYLIST_MODE_LOCAL; @@ -110,10 +110,11 @@ gpgme_new (gpgme_ctx_t *r_ctx) ctx->lc_ctype = strdup (def_lc_ctype); if (!ctx->lc_ctype) { + int saved_err = gpg_error_from_syserror (); UNLOCK (def_lc_lock); _gpgme_engine_info_release (ctx->engine_info); free (ctx); - return TRACE_ERR (gpg_error_from_errno (errno)); + return TRACE_ERR (saved_err); } } else @@ -124,12 +125,13 @@ gpgme_new (gpgme_ctx_t *r_ctx) ctx->lc_messages = strdup (def_lc_messages); if (!ctx->lc_messages) { + int saved_err = gpg_error_from_syserror (); UNLOCK (def_lc_lock); if (ctx->lc_ctype) free (ctx->lc_ctype); _gpgme_engine_info_release (ctx->engine_info); free (ctx); - return TRACE_ERR (gpg_error_from_errno (errno)); + return TRACE_ERR (saved_err); } } else @@ -676,14 +678,14 @@ gpgme_set_locale (gpgme_ctx_t ctx, int category, const char *value) if (failed) { - int saved_errno = errno; + int saved_err = gpg_error_from_syserror (); if (new_lc_ctype) free (new_lc_ctype); if (new_lc_messages) free (new_lc_messages); - return TRACE_ERR (gpg_error_from_errno (saved_errno)); + return TRACE_ERR (saved_err); } #define SET_ONE_LOCALE(lcat, ucat) \ -- cgit v1.2.3