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/engine-gpgconf.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/engine-gpgconf.c')
| -rw-r--r-- | src/engine-gpgconf.c | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/engine-gpgconf.c b/src/engine-gpgconf.c index a2407ac7..4369f272 100644 --- a/src/engine-gpgconf.c +++ b/src/engine-gpgconf.c @@ -46,6 +46,7 @@ #include "debug.h" #include "engine-backend.h" +#include "mem.h" struct engine_gpgconf @@ -81,11 +82,11 @@ gpgconf_release (void *engine) return; if (gpgconf->file_name) - free (gpgconf->file_name); + _gpgme_free (gpgconf->file_name); if (gpgconf->home_dir) - free (gpgconf->home_dir); + _gpgme_free (gpgconf->home_dir); - free (gpgconf); + _gpgme_free (gpgconf); } @@ -95,18 +96,18 @@ gpgconf_new (void **engine, const char *file_name, const char *home_dir) gpgme_error_t err = 0; engine_gpgconf_t gpgconf; - gpgconf = calloc (1, sizeof *gpgconf); + gpgconf = _gpgme_calloc (1, sizeof *gpgconf); if (!gpgconf) return gpg_error_from_syserror (); - gpgconf->file_name = strdup (file_name ? file_name + gpgconf->file_name = _gpgme_strdup (file_name ? file_name : _gpgme_get_default_gpgconf_name ()); if (!gpgconf->file_name) err = gpg_error_from_syserror (); if (!err && home_dir) { - gpgconf->home_dir = strdup (home_dir); + gpgconf->home_dir = _gpgme_strdup (home_dir); if (!gpgconf->home_dir) err = gpg_error_from_syserror (); } @@ -128,8 +129,8 @@ release_arg (gpgme_conf_arg_t arg, gpgme_conf_type_t alt_type) gpgme_conf_arg_t next = arg->next; if (alt_type == GPGME_CONF_STRING) - free (arg->value.string); - free (arg); + _gpgme_free (arg->value.string); + _gpgme_free (arg); arg = next; } } @@ -139,21 +140,21 @@ static void release_opt (gpgme_conf_opt_t opt) { if (opt->name) - free (opt->name); + _gpgme_free (opt->name); if (opt->description) - free (opt->description); + _gpgme_free (opt->description); if (opt->argname) - free (opt->argname); + _gpgme_free (opt->argname); release_arg (opt->default_value, opt->alt_type); if (opt->default_description) - free (opt->default_description); + _gpgme_free (opt->default_description); release_arg (opt->no_arg_value, opt->alt_type); release_arg (opt->value, opt->alt_type); release_arg (opt->new_value, opt->alt_type); - free (opt); + _gpgme_free (opt); } @@ -163,11 +164,11 @@ release_comp (gpgme_conf_comp_t comp) gpgme_conf_opt_t opt; if (comp->name) - free (comp->name); + _gpgme_free (comp->name); if (comp->description) - free (comp->description); + _gpgme_free (comp->description); if (comp->program_name) - free (comp->program_name); + _gpgme_free (comp->program_name); opt = comp->options; while (opt) @@ -177,7 +178,7 @@ release_comp (gpgme_conf_comp_t comp) opt = next; } - free (comp); + _gpgme_free (comp); } @@ -238,7 +239,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2, } linebufsize = 1024; /* Usually enough for conf lines. */ - linebuf = malloc (linebufsize); + linebuf = _gpgme_malloc (linebufsize); if (!linebuf) { err = gpg_error_from_syserror (); @@ -298,7 +299,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2, goto leave; } - newlinebuf = realloc (linebuf, linebufsize); + newlinebuf = _gpgme_realloc (linebuf, linebufsize); if (!newlinebuf) { err = gpg_error_from_syserror (); @@ -309,7 +310,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2, } leave: - free (linebuf); + _gpgme_free (linebuf); _gpgme_io_close (rp[0]); return err; } @@ -342,24 +343,24 @@ gpgconf_config_load_cb (void *hook, char *line) if (comp) comp_p = &comp->next; - comp = calloc (1, sizeof (*comp)); + comp = _gpgme_calloc (1, sizeof (*comp)); if (!comp) return gpg_error_from_syserror (); /* Prepare return value. */ comp->_last_opt_p = &comp->options; *comp_p = comp; - comp->name = strdup (field[0]); + comp->name = _gpgme_strdup (field[0]); if (!comp->name) return gpg_error_from_syserror (); - comp->description = strdup (field[1]); + comp->description = _gpgme_strdup (field[1]); if (!comp->description) return gpg_error_from_syserror (); if (fields >= 3) { - comp->program_name = strdup (field[2]); + comp->program_name = _gpgme_strdup (field[2]); if (!comp->program_name) return gpg_error_from_syserror (); } @@ -386,7 +387,7 @@ gpgconf_parse_option (gpgme_conf_opt_t opt, if (mark) *mark = '\0'; - arg = calloc (1, sizeof (*arg)); + arg = _gpgme_calloc (1, sizeof (*arg)); if (!arg) return gpg_error_from_syserror (); *arg_p = arg; @@ -462,7 +463,7 @@ gpgconf_config_load_cb2 (void *hook, char *line) if (fields < 10) return trace_gpg_error (GPG_ERR_INV_ENGINE); - opt = calloc (1, sizeof (*opt)); + opt = _gpgme_calloc (1, sizeof (*opt)); if (!opt) return gpg_error_from_syserror (); @@ -471,7 +472,7 @@ gpgconf_config_load_cb2 (void *hook, char *line) if (field[0][0]) { - opt->name = strdup (field[0]); + opt->name = _gpgme_strdup (field[0]); if (!opt->name) return gpg_error_from_syserror (); } @@ -482,7 +483,7 @@ gpgconf_config_load_cb2 (void *hook, char *line) if (field[3][0]) { - opt->description = strdup (field[3]); + opt->description = _gpgme_strdup (field[3]); if (!opt->description) return gpg_error_from_syserror (); } @@ -493,7 +494,7 @@ gpgconf_config_load_cb2 (void *hook, char *line) if (field[6][0]) { - opt->argname = strdup (field[6]); + opt->argname = _gpgme_strdup (field[6]); if (!opt->argname) return gpg_error_from_syserror (); } @@ -506,14 +507,14 @@ gpgconf_config_load_cb2 (void *hook, char *line) } else if ((opt->flags & GPGME_CONF_DEFAULT_DESC) && field[7][0]) { - opt->default_description = strdup (field[7]); + opt->default_description = _gpgme_strdup (field[7]); if (!opt->default_description) return gpg_error_from_syserror (); } if (opt->flags & GPGME_CONF_NO_ARG_DESC) { - opt->no_arg_description = strdup (field[8]); + opt->no_arg_description = _gpgme_strdup (field[8]); if (!opt->no_arg_description) return gpg_error_from_syserror (); } @@ -575,7 +576,7 @@ _gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p, { gpgme_conf_arg_t arg; - arg = calloc (1, sizeof (*arg)); + arg = _gpgme_calloc (1, sizeof (*arg)); if (!arg) return gpg_error_from_syserror (); @@ -603,16 +604,16 @@ _gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p, case GPGME_CONF_PUB_KEY: case GPGME_CONF_SEC_KEY: case GPGME_CONF_ALIAS_LIST: - arg->value.string = strdup (value); + arg->value.string = _gpgme_strdup (value); if (!arg->value.string) { - free (arg); + _gpgme_free (arg); return gpg_error_from_syserror (); } break; default: - free (arg); + _gpgme_free (arg); return gpg_error (GPG_ERR_INV_VALUE); } } |
