From aea2c168fc9c12148181dbcc33d7085aad8e6d90 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Fri, 10 Oct 2014 09:02:09 -0400 Subject: 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. --- src/data-mem.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/data-mem.c') diff --git a/src/data-mem.c b/src/data-mem.c index e06a920c..b00e494e 100644 --- a/src/data-mem.c +++ b/src/data-mem.c @@ -33,6 +33,7 @@ #include "data.h" #include "util.h" #include "debug.h" +#include "mem.h" static gpgme_ssize_t @@ -67,7 +68,7 @@ mem_write (gpgme_data_t dh, const void *buffer, size_t size) if (new_size < dh->data.mem.offset + size) new_size = dh->data.mem.offset + size; - new_buffer = malloc (new_size); + new_buffer = _gpgme_malloc (new_size); if (!new_buffer) return -1; memcpy (new_buffer, dh->data.mem.orig_buffer, dh->data.mem.length); @@ -88,12 +89,12 @@ mem_write (gpgme_data_t dh, const void *buffer, size_t size) if (new_size < dh->data.mem.offset + size) new_size = dh->data.mem.offset + size; - new_buffer = realloc (dh->data.mem.buffer, new_size); + new_buffer = _gpgme_realloc (dh->data.mem.buffer, new_size); if (!new_buffer && new_size > dh->data.mem.offset + size) { /* Maybe we were too greedy, try again. */ new_size = dh->data.mem.offset + size; - new_buffer = realloc (dh->data.mem.buffer, new_size); + new_buffer = _gpgme_realloc (dh->data.mem.buffer, new_size); } if (!new_buffer) return -1; @@ -151,7 +152,7 @@ static void mem_release (gpgme_data_t dh) { if (dh->data.mem.buffer) - free (dh->data.mem.buffer); + _gpgme_free (dh->data.mem.buffer); } @@ -199,7 +200,7 @@ gpgme_data_new_from_mem (gpgme_data_t *r_dh, const char *buffer, if (copy) { - char *bufcpy = malloc (size); + char *bufcpy = _gpgme_malloc (size); if (!bufcpy) { int saved_err = gpg_error_from_syserror (); @@ -239,7 +240,7 @@ gpgme_data_release_and_get_mem (gpgme_data_t dh, size_t *r_len) str = dh->data.mem.buffer; if (!str && dh->data.mem.orig_buffer) { - str = malloc (dh->data.mem.length); + str = _gpgme_malloc (dh->data.mem.length); if (!str) { int saved_err = gpg_error_from_syserror (); @@ -278,5 +279,5 @@ gpgme_free (void *buffer) TRACE (DEBUG_DATA, "gpgme_free", buffer); if (buffer) - free (buffer); + _gpgme_free (buffer); } -- cgit v1.2.3