diff options
| author | Ben Kibbey <[email protected]> | 2014-10-10 13:02:09 +0000 |
|---|---|---|
| committer | Ben Kibbey <[email protected]> | 2014-10-16 01:34:10 +0000 |
| commit | aea2c168fc9c12148181dbcc33d7085aad8e6d90 (patch) | |
| tree | 0da3de376e89130822b76edef6d935b294a83d87 /src/gpgme.c | |
| parent | build: Implement SYSROOT feature. (diff) | |
| download | gpgme-aea2c168fc9c12148181dbcc33d7085aad8e6d90.tar.gz gpgme-aea2c168fc9c12148181dbcc33d7085aad8e6d90.zip | |
Add gpgme_set_global_malloc_hooks().
* configure.ac: Remove check for vasprintf().
* doc/gpgme.texi: Add documentation.
* src/gpgme.h.in (gpgme_malloc_hooks,gpgme_malloc_hooks_t): New.
* src/gpgme.h.in (gpgme_set_global_malloc_hooks): New prototype.
* src/mem.c, src/mem.h: New.
* src/gpgme.c (gpgme_set_global_malloc_hooks): New.
* src/gpgme.def, src/libgpgme.vers: Add gpgme_set_global_malloc_hooks.
* src/vasprintf.c (vasprintf): Rename to _gpgme_vasprintf().
* src/vasprintf.c (asprintf): Rename to _gpgme_asprintf().
* src/Makefile.am: Add mem.c, mem.h and vasprintf.c to main_sources.
* src/assuan-support.c, src/ath-pthread.c, src/conversion.c,
src/data-compat.c, src/data-identify.c, src/data-mem.c, src/data.c,
src/debug.c, src/decrypt.c, src/dirinfo.c, src/encrypt.c,
src/engine-assuan.c, src/engine-g13.c, src/engine-gpg.c,
src/engine-gpgconf.c, src/engine-gpgsm.c, src/engine-spawn.c,
src/engine-uiserver.c, src/engine.c, src/export.c, src/genkey.c,
src/get-env.c, src/gpgme-w32spawn.c, src/gpgme.c, src/import.c,
src/key.c, src/keylist.c, src/op-support.c, src/passphrase.c,
src/posix-io.c, src/posix-util.c, src/progress.c, src/setenv.c,
src/sig-notation.c, src/sign.c, src/signers.c, src/trust-item.c,
src/trustlist.c, src/util.h, src/verify.c, src/version.c,
src/vfs-create.c, src/vfs-mount.c, src/w32-ce.c, src/w32-ce.h,
src/w32-glib-io.c, src/w32-io.c, src/w32-sema.c, src/w32-util.c,
src/wait-global.c, src/wait.c:
Change allocation functions: free() to _gpgme_free(), malloc() to
_gpgme_malloc(), calloc() to _gpgme_calloc(), realloc() to
_gpgme_realloc() and strdup() to _gpgme_strdup().
--
Mostly borrowed from libassuan for custom memory handling. This changes
vasprintf.c to implement _gpgme_asprintf() and _gpgme_vasprintf() and
will always use the built-in vasprintf() even when provided by the OS.
Diffstat (limited to 'src/gpgme.c')
| -rw-r--r-- | src/gpgme.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/gpgme.c b/src/gpgme.c index 628cdaee..c76602fe 100644 --- a/src/gpgme.c +++ b/src/gpgme.c @@ -38,6 +38,7 @@ #include "debug.h" #include "priv-io.h" #include "sys-util.h" +#include "mem.h" /* The default locale. */ @@ -52,6 +53,14 @@ gpgme_error_t _gpgme_selftest = GPG_ERR_NOT_OPERATIONAL; accesses to a result structure are read only. */ DEFINE_STATIC_LOCK (result_ref_lock); + +/* Set the default malloc hooks. */ +void +gpgme_set_global_malloc_hooks (gpgme_malloc_hooks_t malloc_hooks) +{ + _gpgme_set_global_malloc_hooks (malloc_hooks); +} + /* Set the global flag NAME to VALUE. Return 0 on success. Note that this function does not use gpgme_error and thus a non-zero return @@ -96,7 +105,7 @@ gpgme_new (gpgme_ctx_t *r_ctx) if (!r_ctx) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); - ctx = calloc (1, sizeof *ctx); + ctx = _gpgme_calloc (1, sizeof *ctx); if (!ctx) return TRACE_ERR (gpg_error_from_syserror ()); @@ -107,7 +116,7 @@ gpgme_new (gpgme_ctx_t *r_ctx) err = gpg_error (GPG_ERR_NO_ENGINE); if (err) { - free (ctx); + _gpgme_free (ctx); return TRACE_ERR (err); } @@ -120,13 +129,13 @@ gpgme_new (gpgme_ctx_t *r_ctx) LOCK (def_lc_lock); if (def_lc_ctype) { - ctx->lc_ctype = strdup (def_lc_ctype); + ctx->lc_ctype = _gpgme_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); + _gpgme_free (ctx); return TRACE_ERR (saved_err); } } @@ -135,15 +144,15 @@ gpgme_new (gpgme_ctx_t *r_ctx) if (def_lc_messages) { - ctx->lc_messages = strdup (def_lc_messages); + ctx->lc_messages = _gpgme_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_free (ctx->lc_ctype); _gpgme_engine_info_release (ctx->engine_info); - free (ctx); + _gpgme_free (ctx); return TRACE_ERR (saved_err); } } @@ -239,15 +248,15 @@ gpgme_release (gpgme_ctx_t ctx) _gpgme_signers_clear (ctx); _gpgme_sig_notation_clear (ctx); if (ctx->signers) - free (ctx->signers); + _gpgme_free (ctx->signers); if (ctx->lc_ctype) - free (ctx->lc_ctype); + _gpgme_free (ctx->lc_ctype); if (ctx->lc_messages) - free (ctx->lc_messages); + _gpgme_free (ctx->lc_messages); _gpgme_engine_info_release (ctx->engine_info); ctx->engine_info = NULL; DESTROY_LOCK (ctx->lock); - free (ctx); + _gpgme_free (ctx); } @@ -291,7 +300,7 @@ gpgme_result_unref (void *result) if (data->cleanup) (*data->cleanup) (data->hook); - free (data); + _gpgme_free (data); } @@ -745,7 +754,7 @@ gpgme_set_locale (gpgme_ctx_t ctx, int category, const char *value) if (!failed && value \ && (category == LC_ALL || category == LC_ ## ucat)) \ { \ - new_lc_ ## lcat = strdup (value); \ + new_lc_ ## lcat = _gpgme_strdup (value); \ if (!new_lc_ ## lcat) \ failed = 1; \ } @@ -762,9 +771,9 @@ gpgme_set_locale (gpgme_ctx_t ctx, int category, const char *value) int saved_err = gpg_error_from_syserror (); if (new_lc_ctype) - free (new_lc_ctype); + _gpgme_free (new_lc_ctype); if (new_lc_messages) - free (new_lc_messages); + _gpgme_free (new_lc_messages); return TRACE_ERR (saved_err); } @@ -775,13 +784,13 @@ gpgme_set_locale (gpgme_ctx_t ctx, int category, const char *value) if (ctx) \ { \ if (ctx->lc_ ## lcat) \ - free (ctx->lc_ ## lcat); \ + _gpgme_free (ctx->lc_ ## lcat); \ ctx->lc_ ## lcat = new_lc_ ## lcat; \ } \ else \ { \ if (def_lc_ ## lcat) \ - free (def_lc_ ## lcat); \ + _gpgme_free (def_lc_ ## lcat); \ def_lc_ ## lcat = new_lc_ ## lcat; \ } \ } |
