aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32-util.c
diff options
context:
space:
mode:
authorBen Kibbey <[email protected]>2014-10-10 13:02:09 +0000
committerBen Kibbey <[email protected]>2014-10-16 01:34:10 +0000
commitaea2c168fc9c12148181dbcc33d7085aad8e6d90 (patch)
tree0da3de376e89130822b76edef6d935b294a83d87 /src/w32-util.c
parentbuild: Implement SYSROOT feature. (diff)
downloadgpgme-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/w32-util.c')
-rw-r--r--src/w32-util.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/w32-util.c b/src/w32-util.c
index daf3bd2d..6f510b30 100644
--- a/src/w32-util.c
+++ b/src/w32-util.c
@@ -141,14 +141,14 @@ wchar_to_utf8 (const wchar_t *string)
return NULL;
}
- result = malloc (n+1);
+ result = _gpgme_malloc (n+1);
if (!result)
return NULL;
n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
if (n < 0)
{
- free (result);
+ _gpgme_free (result);
gpg_err_set_errno (EINVAL);
result = NULL;
}
@@ -276,12 +276,12 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
goto leave;
}
n1 = nbytes + 1;
- result = malloc (n1);
+ result = _gpgme_malloc (n1);
if (!result)
goto leave;
if (RegQueryValueExA (key_handle, name, 0, &type, (LPBYTE) result, &n1))
{
- free (result);
+ _gpgme_free (result);
result = NULL;
goto leave;
}
@@ -294,42 +294,42 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
char *tmp;
n1 += 1000;
- tmp = malloc (n1 + 1);
+ tmp = _gpgme_malloc (n1 + 1);
if (!tmp)
goto leave;
nbytes = ExpandEnvironmentStrings (result, tmp, n1);
if (nbytes && nbytes > n1)
{
- free (tmp);
+ _gpgme_free (tmp);
n1 = nbytes;
- tmp = malloc (n1 + 1);
+ tmp = _gpgme_malloc (n1 + 1);
if (!tmp)
goto leave;
nbytes = ExpandEnvironmentStrings (result, tmp, n1);
if (nbytes && nbytes > n1) {
- free (tmp); /* Oops - truncated, better don't expand at all. */
+ _gpgme_free (tmp); /* Oops - truncated, better don't expand at all. */
goto leave;
}
tmp[nbytes] = 0;
- free (result);
+ _gpgme_free (result);
result = tmp;
}
else if (nbytes) /* Okay, reduce the length. */
{
tmp[nbytes] = 0;
- free (result);
- result = malloc (strlen (tmp)+1);
+ _gpgme_free (result);
+ result = _gpgme_malloc (strlen (tmp)+1);
if (!result)
result = tmp;
else
{
strcpy (result, tmp);
- free (tmp);
+ _gpgme_free (tmp);
}
}
else /* Error - don't expand. */
{
- free (tmp);
+ _gpgme_free (tmp);
}
}
#endif
@@ -352,7 +352,7 @@ _gpgme_get_inst_dir (void)
{
wchar_t *moddir;
- moddir = malloc ((MAX_PATH+5) * sizeof *moddir);
+ moddir = _gpgme_malloc ((MAX_PATH+5) * sizeof *moddir);
if (moddir)
{
if (!GetModuleFileNameW (my_hmodule, moddir, MAX_PATH))
@@ -369,7 +369,7 @@ _gpgme_get_inst_dir (void)
*p = 0;
}
}
- free (moddir);
+ _gpgme_free (moddir);
}
}
UNLOCK (get_path_lock);
@@ -382,14 +382,14 @@ find_program_in_dir (const char *dir, const char *name)
{
char *result;
- result = malloc (strlen (dir) + 1 + strlen (name) + 1);
+ result = _gpgme_malloc (strlen (dir) + 1 + strlen (name) + 1);
if (!result)
return NULL;
strcpy (stpcpy (stpcpy (result, dir), "\\"), name);
if (access (result, F_OK))
{
- free (result);
+ _gpgme_free (result);
return NULL;
}
@@ -424,7 +424,7 @@ find_program_in_inst_dir (const char *inst_dir, const char *name)
if (dir)
{
result = find_program_in_dir (dir, name);
- free (dir);
+ _gpgme_free (dir);
return result;
}
return NULL;
@@ -440,13 +440,13 @@ find_program_at_standard_place (const char *name)
/* See http://wiki.tcl.tk/17492 for details on compatibility. */
if (SHGetSpecialFolderPathA (NULL, path, CSIDL_PROGRAM_FILES, 0))
{
- result = malloc (strlen (path) + 1 + strlen (name) + 1);
+ result = _gpgme_malloc (strlen (path) + 1 + strlen (name) + 1);
if (result)
{
strcpy (stpcpy (stpcpy (result, path), "\\"), name);
if (access (result, F_OK))
{
- free (result);
+ _gpgme_free (result);
result = NULL;
}
}
@@ -462,7 +462,7 @@ _gpgme_set_default_gpg_name (const char *name)
{
if (!default_gpg_name)
{
- default_gpg_name = malloc (strlen (name) + 5);
+ default_gpg_name = _gpgme_malloc (strlen (name) + 5);
if (default_gpg_name)
{
strcpy (stpcpy (default_gpg_name, name), ".exe");
@@ -479,7 +479,7 @@ _gpgme_set_default_gpgconf_name (const char *name)
{
if (!default_gpgconf_name)
{
- default_gpgconf_name = malloc (strlen (name) + 5);
+ default_gpgconf_name = _gpgme_malloc (strlen (name) + 5);
if (default_gpgconf_name)
{
strcpy (stpcpy (default_gpgconf_name, name), ".exe");
@@ -571,7 +571,7 @@ _gpgme_get_conf_int (const char *key, int *value)
if (!tmp)
return 0;
*value = atoi (tmp);
- free (tmp);
+ _gpgme_free (tmp);
return 1;
}
@@ -704,14 +704,14 @@ _gpgme_mkstemp (int *fd, char **name)
}
}
- tmpname = malloc (strlen (tmp) + 13 + 1);
+ tmpname = _gpgme_malloc (strlen (tmp) + 13 + 1);
if (!tmpname)
return -1;
strcpy (stpcpy (tmpname, tmp), "\\gpgme-XXXXXX");
*fd = mkstemp (tmpname);
if (fd < 0)
{
- free (tmpname);
+ _gpgme_free (tmpname);
return -1;
}
@@ -734,7 +734,7 @@ _gpgme_w32ce_get_debug_envvar (void)
tmp = read_w32_registry_string (NULL, "\\Software\\GNU\\gpgme", "debug");
if (tmp && !*tmp)
{
- free (tmp);
+ _gpgme_free (tmp);
tmp = NULL;
}
return tmp;