Compare commits

...

2 Commits

Author SHA1 Message Date
Ben Kibbey
fff2049c1b Fix crash with built-in [v]asprintf().
* src/vasprintf.c (__gpgme_vasprintf): Copy the va_list.
--
Not sure why it needs to be done. Maybe because of dereferencing the
pointer while doing va_copy() int_vasprintf()? If we remove the
_BSD_VA_LIST stuff and pass a regular va_list all is fine.
2014-10-16 19:32:13 -04:00
Ben Kibbey
aea2c168fc 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.
2014-10-15 21:34:10 -04:00
60 changed files with 803 additions and 562 deletions

View File

@ -371,11 +371,7 @@ fi
AC_MSG_NOTICE([checking for libraries]) AC_MSG_NOTICE([checking for libraries])
AC_FUNC_FSEEKO AC_FUNC_FSEEKO
GNUPG_CHECK_VA_COPY
AC_REPLACE_FUNCS(vasprintf)
if test "$ac_cv_func_vasprintf" != yes; then
GNUPG_CHECK_VA_COPY
fi
# Try to find a thread-safe version of ttyname(). # Try to find a thread-safe version of ttyname().
gnupg_REPLACE_TTYNAME_R gnupg_REPLACE_TTYNAME_R

View File

@ -129,6 +129,7 @@ Preparation
* Largefile Support (LFS):: How to use @acronym{GPGME} with LFS. * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
* Using Automake:: Compiler options to be used the easy way. * Using Automake:: Compiler options to be used the easy way.
* Using Libtool:: Avoiding compiler options entirely. * Using Libtool:: Avoiding compiler options entirely.
* Custom Memory Functions:: Using your own memory allocators.
* Library Version Check:: Getting and verifying the library version. * Library Version Check:: Getting and verifying the library version.
* Signal Handling:: How @acronym{GPGME} affects signal handling. * Signal Handling:: How @acronym{GPGME} affects signal handling.
* Multi Threading:: How @acronym{GPGME} can be used in an MT environment. * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
@ -365,6 +366,7 @@ of the library are verified.
* Largefile Support (LFS):: How to use @acronym{GPGME} with LFS. * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
* Using Automake:: Compiler options to be used the easy way. * Using Automake:: Compiler options to be used the easy way.
* Using Libtool:: Avoiding compiler options entirely. * Using Libtool:: Avoiding compiler options entirely.
* Custom Memory Functions:: Using your own memory allocators.
* Library Version Check:: Getting and verifying the library version. * Library Version Check:: Getting and verifying the library version.
* Signal Handling:: How @acronym{GPGME} affects signal handling. * Signal Handling:: How @acronym{GPGME} affects signal handling.
* Multi Threading:: How @acronym{GPGME} can be used in an MT environment. * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
@ -618,6 +620,50 @@ link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
automatically by Libtool. automatically by Libtool.
@node Custom Memory Functions
@section Custom Memory Functions
@cindex Using your own memory allocators
If your application uses its own memory allocation functions or wrappers
it is good idea to tell @code{libgpgme} about it so it can make use of the
same functions or wrappers:
@deftp {Data type} {struct gpgme_malloc_hooks}
This structure is used to store the memory allocation callback
interface functions. It has the following members, whose semantics
are identical to the corresponding system functions:
@table @code
@item void *(*malloc) (size_t cnt)
This is the function called by @acronym{GPGME} to allocate memory for a
context.
@item void *(*calloc) (size_t nmemb, size_t cnt)
This is the function called by @acronym{GPGME} to allocate memory for a
context and zero its contents.
@item void *(*realloc) (void *ptr, size_t cnt)
This is the function called by @acronym{GPGME} to reallocate memory for a
context.
@item void (*free) (void *ptr)
This is the function called by @acronym{GPGME} to release memory for a
context.
@end table
@end deftp
@deftp {Data type} {gpgme_malloc_hooks_t}
This is a pointer to a @code{struct gpgme_malloc_hooks}.
@end deftp
@deftypefun void gpgme_set_global_malloc_hooks (@w{gpgme_malloc_hooks_t @var{malloc_hooks}})
This function sets the default allocation hooks for all memory operations.
You need to provide all four functions. Those functions need to behave
exactly as their standard counterparts @code{malloc}, @code{calloc},
@code{realloc} and @code{free}. If you write your own functions, please take
care to set @code{errno} whenever an error has occurred.
@end deftypefun
@node Library Version Check @node Library Version Check
@section Library Version Check @section Library Version Check
@cindex version check, of the library @cindex version check, of the library

View File

@ -99,7 +99,8 @@ main_sources = \
engine-spawn.c \ engine-spawn.c \
gpgconf.c \ gpgconf.c \
sema.h priv-io.h $(system_components) sys-util.h dirinfo.c \ sema.h priv-io.h $(system_components) sys-util.h dirinfo.c \
debug.c debug.h gpgme.c version.c error.c debug.c debug.h gpgme.c version.c error.c mem.c mem.h \
vasprintf.c
libgpgme_la_SOURCES = $(main_sources) \ libgpgme_la_SOURCES = $(main_sources) \
ath.h ath.c $(system_components_not_extra) ath.h ath.c $(system_components_not_extra)

View File

@ -12,13 +12,32 @@
#include "ath.h" #include "ath.h"
#include "priv-io.h" #include "priv-io.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
static void *
_gpgme_assuan_malloc (size_t size)
{
return _gpgme_malloc (size);
}
static void *
_gpgme_assuan_realloc (void *p, size_t size)
{
return _gpgme_realloc (p, size);
}
static void
_gpgme_assuan_free (void *p)
{
_gpgme_free (p);
}
struct assuan_malloc_hooks _gpgme_assuan_malloc_hooks = struct assuan_malloc_hooks _gpgme_assuan_malloc_hooks =
{ {
malloc, _gpgme_assuan_malloc,
realloc, _gpgme_assuan_realloc,
free _gpgme_assuan_free
}; };
@ -140,7 +159,7 @@ my_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
} }
/* fd_in, fd_out, terminator */ /* fd_in, fd_out, terminator */
i += 3; i += 3;
fd_items = calloc (i, sizeof (struct spawn_fd_item_s)); fd_items = _gpgme_calloc (i, sizeof (struct spawn_fd_item_s));
if (! fd_items) if (! fd_items)
return -1; return -1;
i = 0; i = 0;
@ -184,7 +203,7 @@ my_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
} }
} }
} }
free (fd_items); _gpgme_free (fd_items);
return err; return err;
} }

View File

@ -42,6 +42,7 @@
#include "gpgme.h" #include "gpgme.h"
#include "ath.h" #include "ath.h"
#include "mem.h"
/* The lock we take while checking for lazy lock initialization. */ /* The lock we take while checking for lazy lock initialization. */
@ -58,14 +59,14 @@ mutex_pthread_init (ath_mutex_t *priv, int just_check)
pthread_mutex_lock (&check_init_lock); pthread_mutex_lock (&check_init_lock);
if (!*priv || !just_check) if (!*priv || !just_check)
{ {
pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t)); pthread_mutex_t *lock = _gpgme_malloc (sizeof (pthread_mutex_t));
if (!lock) if (!lock)
err = ENOMEM; err = ENOMEM;
if (!err) if (!err)
{ {
err = pthread_mutex_init (lock, NULL); err = pthread_mutex_init (lock, NULL);
if (err) if (err)
free (lock); _gpgme_free (lock);
else else
*priv = (ath_mutex_t) lock; *priv = (ath_mutex_t) lock;
} }
@ -104,7 +105,7 @@ ath_mutex_destroy (ath_mutex_t *lock)
if (!err) if (!err)
{ {
err = pthread_mutex_destroy ((pthread_mutex_t *) *lock); err = pthread_mutex_destroy ((pthread_mutex_t *) *lock);
free (*lock); _gpgme_free (*lock);
} }
return err; return err;
} }

View File

@ -35,6 +35,7 @@
#include "gpgme.h" #include "gpgme.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
#define atoi_1(p) (*(p) - '0' ) #define atoi_1(p) (*(p) - '0' )
#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1)) #define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
@ -93,7 +94,7 @@ _gpgme_decode_c_string (const char *src, char **destp, size_t len)
{ {
/* The converted string will never be larger than the original /* The converted string will never be larger than the original
string. */ string. */
dest = malloc (strlen (src) + 1); dest = _gpgme_malloc (strlen (src) + 1);
if (!dest) if (!dest)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -198,7 +199,7 @@ _gpgme_decode_percent_string (const char *src, char **destp, size_t len,
{ {
/* The converted string will never be larger than the original /* The converted string will never be larger than the original
string. */ string. */
dest = malloc (strlen (src) + 1); dest = _gpgme_malloc (strlen (src) + 1);
if (!dest) if (!dest)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -291,7 +292,7 @@ _gpgme_encode_percent_string (const char *src, char **destp, size_t len)
{ {
/* The converted string will never be larger than the original /* The converted string will never be larger than the original
string. */ string. */
dest = malloc (destlen); dest = _gpgme_malloc (destlen);
if (!dest) if (!dest)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();

View File

@ -34,6 +34,7 @@
#include "data.h" #include "data.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* Create a new data buffer filled with LENGTH bytes starting from /* Create a new data buffer filled with LENGTH bytes starting from
@ -77,7 +78,7 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname,
return TRACE_ERR (saved_err); return TRACE_ERR (saved_err);
} }
buf = malloc (length); buf = _gpgme_malloc (length);
if (!buf) if (!buf)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
@ -92,7 +93,7 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname,
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
if (buf) if (buf)
free (buf); _gpgme_free (buf);
if (fname) if (fname)
fclose (stream); fclose (stream);
return TRACE_ERR (saved_err); return TRACE_ERR (saved_err);
@ -105,7 +106,7 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname,
if (err) if (err)
{ {
if (buf) if (buf)
free (buf); _gpgme_free (buf);
return err; return err;
} }

View File

@ -28,6 +28,7 @@
#include "data.h" #include "data.h"
#include "util.h" #include "util.h"
#include "parsetlv.h" #include "parsetlv.h"
#include "mem.h"
/* The size of the sample data we take for detection. */ /* The size of the sample data we take for detection. */
#define SAMPLE_SIZE 2048 #define SAMPLE_SIZE 2048
@ -228,19 +229,19 @@ gpgme_data_identify (gpgme_data_t dh, int reserved)
return GPGME_DATA_TYPE_INVALID; return GPGME_DATA_TYPE_INVALID;
/* Allocate a buffer and read the data. */ /* Allocate a buffer and read the data. */
sample = malloc (SAMPLE_SIZE); sample = _gpgme_malloc (SAMPLE_SIZE);
if (!sample) if (!sample)
return GPGME_DATA_TYPE_INVALID; /* Ooops. */ return GPGME_DATA_TYPE_INVALID; /* Ooops. */
n = gpgme_data_read (dh, sample, SAMPLE_SIZE - 1); n = gpgme_data_read (dh, sample, SAMPLE_SIZE - 1);
if (n < 0) if (n < 0)
{ {
free (sample); _gpgme_free (sample);
return GPGME_DATA_TYPE_INVALID; /* Ooops. */ return GPGME_DATA_TYPE_INVALID; /* Ooops. */
} }
sample[n] = 0; /* (Required for our string functions.) */ sample[n] = 0; /* (Required for our string functions.) */
result = basic_detection (sample, n); result = basic_detection (sample, n);
free (sample); _gpgme_free (sample);
gpgme_data_seek (dh, off, SEEK_SET); gpgme_data_seek (dh, off, SEEK_SET);
return result; return result;

View File

@ -33,6 +33,7 @@
#include "data.h" #include "data.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
static gpgme_ssize_t 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) if (new_size < dh->data.mem.offset + size)
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) if (!new_buffer)
return -1; return -1;
memcpy (new_buffer, dh->data.mem.orig_buffer, dh->data.mem.length); 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) if (new_size < dh->data.mem.offset + size)
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) if (!new_buffer && new_size > dh->data.mem.offset + size)
{ {
/* Maybe we were too greedy, try again. */ /* Maybe we were too greedy, try again. */
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) if (!new_buffer)
return -1; return -1;
@ -151,7 +152,7 @@ static void
mem_release (gpgme_data_t dh) mem_release (gpgme_data_t dh)
{ {
if (dh->data.mem.buffer) 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) if (copy)
{ {
char *bufcpy = malloc (size); char *bufcpy = _gpgme_malloc (size);
if (!bufcpy) if (!bufcpy)
{ {
int saved_err = gpg_error_from_syserror (); 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; str = dh->data.mem.buffer;
if (!str && dh->data.mem.orig_buffer) if (!str && dh->data.mem.orig_buffer)
{ {
str = malloc (dh->data.mem.length); str = _gpgme_malloc (dh->data.mem.length);
if (!str) if (!str)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
@ -278,5 +279,5 @@ gpgme_free (void *buffer)
TRACE (DEBUG_DATA, "gpgme_free", buffer); TRACE (DEBUG_DATA, "gpgme_free", buffer);
if (buffer) if (buffer)
free (buffer); _gpgme_free (buffer);
} }

View File

@ -35,6 +35,7 @@
#include "ops.h" #include "ops.h"
#include "priv-io.h" #include "priv-io.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
gpgme_error_t gpgme_error_t
@ -46,7 +47,7 @@ _gpgme_data_new (gpgme_data_t *r_dh, struct _gpgme_data_cbs *cbs)
return gpg_error (GPG_ERR_INV_VALUE); return gpg_error (GPG_ERR_INV_VALUE);
*r_dh = NULL; *r_dh = NULL;
dh = calloc (1, sizeof (*dh)); dh = _gpgme_calloc (1, sizeof (*dh));
if (!dh) if (!dh)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -64,8 +65,8 @@ _gpgme_data_release (gpgme_data_t dh)
return; return;
if (dh->file_name) if (dh->file_name)
free (dh->file_name); _gpgme_free (dh->file_name);
free (dh); _gpgme_free (dh);
} }
@ -212,11 +213,11 @@ gpgme_data_set_file_name (gpgme_data_t dh, const char *file_name)
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
if (dh->file_name) if (dh->file_name)
free (dh->file_name); _gpgme_free (dh->file_name);
if (file_name) if (file_name)
{ {
dh->file_name = strdup (file_name); dh->file_name = _gpgme_strdup (file_name);
if (!dh->file_name) if (!dh->file_name)
return TRACE_ERR (gpg_error_from_syserror ()); return TRACE_ERR (gpg_error_from_syserror ());
} }

View File

@ -47,6 +47,7 @@
#include "ath.h" #include "ath.h"
#include "sema.h" #include "sema.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* Lock to serialize initialization of the debug output subsystem and /* Lock to serialize initialization of the debug output subsystem and
@ -122,8 +123,8 @@ trim_spaces (char *str)
int int
_gpgme_debug_set_debug_envvar (const char *value) _gpgme_debug_set_debug_envvar (const char *value)
{ {
free (envvar_override); _gpgme_free (envvar_override);
envvar_override = strdup (value); envvar_override = _gpgme_strdup (value);
return !envvar_override; return !envvar_override;
} }
@ -142,8 +143,8 @@ debug_init (void)
if (envvar_override) if (envvar_override)
{ {
e = strdup (envvar_override); e = _gpgme_strdup (envvar_override);
free (envvar_override); _gpgme_free (envvar_override);
envvar_override = NULL; envvar_override = NULL;
} }
else else
@ -182,7 +183,7 @@ debug_init (void)
s1++; s1++;
if (!(s2 = strchr (s1, PATHSEP_C))) if (!(s2 = strchr (s1, PATHSEP_C)))
s2 = s1 + strlen (s1); s2 = s1 + strlen (s1);
p = malloc (s2 - s1 + 1); p = _gpgme_malloc (s2 - s1 + 1);
if (p) if (p)
{ {
memcpy (p, s1, s2 - s1); memcpy (p, s1, s2 - s1);
@ -194,13 +195,13 @@ debug_init (void)
setvbuf (fp, NULL, _IOLBF, 0); setvbuf (fp, NULL, _IOLBF, 0);
errfp = fp; errfp = fp;
} }
free (p); _gpgme_free (p);
} }
#ifndef HAVE_DOSISH_SYSTEM #ifndef HAVE_DOSISH_SYSTEM
} }
#endif #endif
} }
free (e); _gpgme_free (e);
} }
} }
UNLOCK (debug_lock); UNLOCK (debug_lock);
@ -292,7 +293,7 @@ _gpgme_debug_begin (void **line, int level, const char *format, ...)
} }
va_start (arg_ptr, format); va_start (arg_ptr, format);
res = vasprintf ((char **) line, format, arg_ptr); res = _gpgme_vasprintf ((char **) line, format, arg_ptr);
va_end (arg_ptr); va_end (arg_ptr);
if (res < 0) if (res < 0)
*line = NULL; *line = NULL;
@ -312,16 +313,16 @@ _gpgme_debug_add (void **line, const char *format, ...)
return; return;
va_start (arg_ptr, format); va_start (arg_ptr, format);
res = vasprintf (&toadd, format, arg_ptr); res = _gpgme_vasprintf (&toadd, format, arg_ptr);
va_end (arg_ptr); va_end (arg_ptr);
if (res < 0) if (res < 0)
{ {
free (*line); _gpgme_free (*line);
*line = NULL; *line = NULL;
} }
res = asprintf (&result, "%s%s", *(char **) line, toadd); res = _gpgme_asprintf (&result, "%s%s", *(char **) line, toadd);
free (toadd); _gpgme_free (toadd);
free (*line); _gpgme_free (*line);
if (res < 0) if (res < 0)
*line = NULL; *line = NULL;
else else
@ -340,7 +341,7 @@ _gpgme_debug_end (void **line)
/* The smallest possible level is 1, so force logging here by /* The smallest possible level is 1, so force logging here by
using that. */ using that. */
_gpgme_debug (1, "%s", *line); _gpgme_debug (1, "%s", *line);
free (*line); _gpgme_free (*line);
*line = NULL; *line = NULL;
} }

View File

@ -31,6 +31,7 @@
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "mem.h"
@ -55,15 +56,15 @@ release_op_data (void *hook)
gpgme_recipient_t recipient = opd->result.recipients; gpgme_recipient_t recipient = opd->result.recipients;
if (opd->result.unsupported_algorithm) if (opd->result.unsupported_algorithm)
free (opd->result.unsupported_algorithm); _gpgme_free (opd->result.unsupported_algorithm);
if (opd->result.file_name) if (opd->result.file_name)
free (opd->result.file_name); _gpgme_free (opd->result.file_name);
while (recipient) while (recipient)
{ {
gpgme_recipient_t next = recipient->next; gpgme_recipient_t next = recipient->next;
free (recipient); _gpgme_free (recipient);
recipient = next; recipient = next;
} }
} }
@ -125,7 +126,7 @@ parse_enc_to (char *args, gpgme_recipient_t *recp, gpgme_protocol_t protocol)
char *tail; char *tail;
int i; int i;
rec = malloc (sizeof (*rec)); rec = _gpgme_malloc (sizeof (*rec));
if (!rec) if (!rec)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -145,7 +146,7 @@ parse_enc_to (char *args, gpgme_recipient_t *recp, gpgme_protocol_t protocol)
args = &args[i]; args = &args[i];
if (*args != '\0' && *args != ' ') if (*args != '\0' && *args != ' ')
{ {
free (rec); _gpgme_free (rec);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
@ -159,7 +160,7 @@ parse_enc_to (char *args, gpgme_recipient_t *recp, gpgme_protocol_t protocol)
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (rec); _gpgme_free (rec);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
} }
@ -242,7 +243,7 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
if (!(*args == '?' && *(args + 1) == '\0')) if (!(*args == '?' && *(args + 1) == '\0'))
{ {
opd->result.unsupported_algorithm = strdup (args); opd->result.unsupported_algorithm = _gpgme_strdup (args);
if (!opd->result.unsupported_algorithm) if (!opd->result.unsupported_algorithm)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }

View File

@ -30,6 +30,7 @@
#include "debug.h" #include "debug.h"
#include "sema.h" #include "sema.h"
#include "sys-util.h" #include "sys-util.h"
#include "mem.h"
DEFINE_STATIC_LOCK (dirinfo_lock); DEFINE_STATIC_LOCK (dirinfo_lock);
@ -101,11 +102,11 @@ parse_output (char *line, int components)
if (components) if (components)
{ {
if (!strcmp (line, "gpg") && !dirinfo.gpg_name) if (!strcmp (line, "gpg") && !dirinfo.gpg_name)
dirinfo.gpg_name = strdup (value); dirinfo.gpg_name = _gpgme_strdup (value);
else if (!strcmp (line, "gpgsm") && !dirinfo.gpgsm_name) else if (!strcmp (line, "gpgsm") && !dirinfo.gpgsm_name)
dirinfo.gpgsm_name = strdup (value); dirinfo.gpgsm_name = _gpgme_strdup (value);
else if (!strcmp (line, "g13") && !dirinfo.g13_name) else if (!strcmp (line, "g13") && !dirinfo.g13_name)
dirinfo.g13_name = strdup (value); dirinfo.g13_name = _gpgme_strdup (value);
} }
else else
{ {
@ -113,10 +114,10 @@ parse_output (char *line, int components)
{ {
const char name[] = "S.uiserver"; const char name[] = "S.uiserver";
dirinfo.homedir = strdup (value); dirinfo.homedir = _gpgme_strdup (value);
if (dirinfo.homedir) if (dirinfo.homedir)
{ {
dirinfo.uisrv_socket = malloc (strlen (dirinfo dirinfo.uisrv_socket = _gpgme_malloc (strlen (dirinfo
.homedir) .homedir)
+ 1 + strlen (name) + 1); + 1 + strlen (name) + 1);
if (dirinfo.uisrv_socket) if (dirinfo.uisrv_socket)
@ -125,7 +126,7 @@ parse_output (char *line, int components)
} }
} }
else if (!strcmp (line, "agent-socket") && !dirinfo.agent_socket) else if (!strcmp (line, "agent-socket") && !dirinfo.agent_socket)
dirinfo.agent_socket = strdup (value); dirinfo.agent_socket = _gpgme_strdup (value);
} }
} }
@ -216,7 +217,7 @@ get_gpgconf_item (int what)
{ {
_gpgme_debug (DEBUG_INIT, _gpgme_debug (DEBUG_INIT,
"gpgme-dinfo: gpgconf='%s' [not installed]\n", pgmname); "gpgme-dinfo: gpgconf='%s' [not installed]\n", pgmname);
free (pgmname); _gpgme_free (pgmname);
pgmname = NULL; /* Not available. */ pgmname = NULL; /* Not available. */
} }
else else

View File

@ -30,6 +30,7 @@
#include "debug.h" #include "debug.h"
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "mem.h"
typedef struct typedef struct
@ -53,8 +54,8 @@ release_op_data (void *hook)
{ {
gpgme_invalid_key_t next = invalid_recipient->next; gpgme_invalid_key_t next = invalid_recipient->next;
if (invalid_recipient->fpr) if (invalid_recipient->fpr)
free (invalid_recipient->fpr); _gpgme_free (invalid_recipient->fpr);
free (invalid_recipient); _gpgme_free (invalid_recipient);
invalid_recipient = next; invalid_recipient = next;
} }
} }

View File

@ -53,6 +53,7 @@
#include "debug.h" #include "debug.h"
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
typedef struct typedef struct
@ -131,7 +132,7 @@ llass_get_home_dir (void)
static char * static char *
llass_get_version (const char *file_name) llass_get_version (const char *file_name)
{ {
return strdup ("1.0"); return _gpgme_strdup ("1.0");
} }
@ -205,7 +206,7 @@ llass_release (void *engine)
llass_cancel (engine); llass_cancel (engine);
free (llass); _gpgme_free (llass);
} }
@ -218,7 +219,7 @@ llass_new (void **engine, const char *file_name, const char *home_dir)
engine_llass_t llass; engine_llass_t llass;
char *optstr; char *optstr;
llass = calloc (1, sizeof *llass); llass = _gpgme_calloc (1, sizeof *llass);
if (!llass) if (!llass)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -259,17 +260,17 @@ llass_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_display) if (dft_display)
{ {
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0) if (_gpgme_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (dft_display); _gpgme_free (dft_display);
goto leave; goto leave;
} }
free (dft_display); _gpgme_free (dft_display);
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -289,14 +290,14 @@ llass_new (void **engine, const char *file_name, const char *home_dir)
} }
else else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
@ -305,17 +306,17 @@ llass_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_ttytype) if (dft_ttytype)
{ {
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (dft_ttytype); _gpgme_free (dft_ttytype);
goto leave; goto leave;
} }
free (dft_ttytype); _gpgme_free (dft_ttytype);
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -393,13 +394,13 @@ llass_set_locale (void *engine, int category, const char *value)
if (!value) if (!value)
return 0; return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0) if (_gpgme_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
{ {
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
} }
return err; return err;
} }

View File

@ -50,6 +50,8 @@
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
typedef struct typedef struct
{ {
@ -207,7 +209,7 @@ g13_release (void *engine)
g13_cancel (engine); g13_cancel (engine);
free (g13); _gpgme_free (g13);
} }
@ -224,7 +226,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
char *dft_ttytype = NULL; char *dft_ttytype = NULL;
char *optstr; char *optstr;
g13 = calloc (1, sizeof *g13); g13 = _gpgme_calloc (1, sizeof *g13);
if (!g13) if (!g13)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -266,17 +268,17 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_display) if (dft_display)
{ {
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0) if (_gpgme_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{ {
free (dft_display); _gpgme_free (dft_display);
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
free (dft_display); _gpgme_free (dft_display);
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -293,14 +295,14 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
} }
else else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
@ -309,17 +311,17 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_ttytype) if (dft_ttytype)
{ {
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{ {
free (dft_ttytype); _gpgme_free (dft_ttytype);
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
free (dft_ttytype); _gpgme_free (dft_ttytype);
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -389,13 +391,13 @@ g13_set_locale (void *engine, int category, const char *value)
if (!value) if (!value)
return 0; return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0) if (_gpgme_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
{ {
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
} }
return err; return err;

View File

@ -44,6 +44,7 @@
#include "debug.h" #include "debug.h"
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
/* This type is used to build a list of gpg arguments and data /* This type is used to build a list of gpg arguments and data
@ -209,7 +210,7 @@ _add_arg (engine_gpg_t gpg, const char *arg, int front, int *arg_locp)
assert (gpg); assert (gpg);
assert (arg); assert (arg);
a = malloc (sizeof *a + strlen (arg)); a = _gpgme_malloc (sizeof *a + strlen (arg));
if (!a) if (!a)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -268,7 +269,7 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
assert (gpg); assert (gpg);
assert (data); assert (data);
a = malloc (sizeof *a - 1); a = _gpgme_malloc (sizeof *a - 1);
if (!a) if (!a)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
a->next = NULL; a->next = NULL;
@ -313,8 +314,8 @@ free_argv (char **argv)
int i; int i;
for (i = 0; argv[i]; i++) for (i = 0; argv[i]; i++)
free (argv[i]); _gpgme_free (argv[i]);
free (argv); _gpgme_free (argv);
} }
@ -334,7 +335,7 @@ free_fd_data_map (struct fd_data_map_s *fd_data_map)
_gpgme_io_close (fd_data_map[i].peer_fd); _gpgme_io_close (fd_data_map[i].peer_fd);
/* Don't release data because this is only a reference. */ /* Don't release data because this is only a reference. */
} }
free (fd_data_map); _gpgme_free (fd_data_map);
} }
@ -385,32 +386,32 @@ gpg_release (void *engine)
gpg_cancel (engine); gpg_cancel (engine);
if (gpg->file_name) if (gpg->file_name)
free (gpg->file_name); _gpgme_free (gpg->file_name);
if (gpg->lc_messages) if (gpg->lc_messages)
free (gpg->lc_messages); _gpgme_free (gpg->lc_messages);
if (gpg->lc_ctype) if (gpg->lc_ctype)
free (gpg->lc_ctype); _gpgme_free (gpg->lc_ctype);
while (gpg->arglist) while (gpg->arglist)
{ {
struct arg_and_data_s *next = gpg->arglist->next; struct arg_and_data_s *next = gpg->arglist->next;
if (gpg->arglist) if (gpg->arglist)
free (gpg->arglist); _gpgme_free (gpg->arglist);
gpg->arglist = next; gpg->arglist = next;
} }
if (gpg->status.buffer) if (gpg->status.buffer)
free (gpg->status.buffer); _gpgme_free (gpg->status.buffer);
if (gpg->colon.buffer) if (gpg->colon.buffer)
free (gpg->colon.buffer); _gpgme_free (gpg->colon.buffer);
if (gpg->argv) if (gpg->argv)
free_argv (gpg->argv); free_argv (gpg->argv);
if (gpg->cmd.keyword) if (gpg->cmd.keyword)
free (gpg->cmd.keyword); _gpgme_free (gpg->cmd.keyword);
free (gpg); _gpgme_free (gpg);
} }
@ -423,13 +424,13 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
char dft_ttyname[64]; char dft_ttyname[64];
char *dft_ttytype = NULL; char *dft_ttytype = NULL;
gpg = calloc (1, sizeof *gpg); gpg = _gpgme_calloc (1, sizeof *gpg);
if (!gpg) if (!gpg)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
if (file_name) if (file_name)
{ {
gpg->file_name = strdup (file_name); gpg->file_name = _gpgme_strdup (file_name);
if (!gpg->file_name) if (!gpg->file_name)
{ {
rc = gpg_error_from_syserror (); rc = gpg_error_from_syserror ();
@ -450,7 +451,7 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
/* Allocate the read buffer for the status pipe. */ /* Allocate the read buffer for the status pipe. */
gpg->status.bufsize = 1024; gpg->status.bufsize = 1024;
gpg->status.readpos = 0; gpg->status.readpos = 0;
gpg->status.buffer = malloc (gpg->status.bufsize); gpg->status.buffer = _gpgme_malloc (gpg->status.bufsize);
if (!gpg->status.buffer) if (!gpg->status.buffer)
{ {
rc = gpg_error_from_syserror (); rc = gpg_error_from_syserror ();
@ -513,7 +514,7 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
if (!rc) if (!rc)
rc = add_arg (gpg, dft_display); rc = add_arg (gpg, dft_display);
free (dft_display); _gpgme_free (dft_display);
} }
if (isatty (1)) if (isatty (1))
@ -546,7 +547,7 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
rc = add_arg (gpg, dft_ttytype); rc = add_arg (gpg, dft_ttytype);
} }
free (dft_ttytype); _gpgme_free (dft_ttytype);
} }
} }
if (rc) if (rc)
@ -574,12 +575,12 @@ gpg_set_locale (void *engine, int category, const char *value)
{ {
if (gpg->lc_ctype) if (gpg->lc_ctype)
{ {
free (gpg->lc_ctype); _gpgme_free (gpg->lc_ctype);
gpg->lc_ctype = NULL; gpg->lc_ctype = NULL;
} }
if (value) if (value)
{ {
gpg->lc_ctype = strdup (value); gpg->lc_ctype = _gpgme_strdup (value);
if (!gpg->lc_ctype) if (!gpg->lc_ctype)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -590,12 +591,12 @@ gpg_set_locale (void *engine, int category, const char *value)
{ {
if (gpg->lc_messages) if (gpg->lc_messages)
{ {
free (gpg->lc_messages); _gpgme_free (gpg->lc_messages);
gpg->lc_messages = NULL; gpg->lc_messages = NULL;
} }
if (value) if (value)
{ {
gpg->lc_messages = strdup (value); gpg->lc_messages = _gpgme_strdup (value);
if (!gpg->lc_messages) if (!gpg->lc_messages)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -629,14 +630,14 @@ gpg_set_colon_line_handler (void *engine, engine_colon_line_handler_t fnc,
gpg->colon.bufsize = 1024; gpg->colon.bufsize = 1024;
gpg->colon.readpos = 0; gpg->colon.readpos = 0;
gpg->colon.buffer = malloc (gpg->colon.bufsize); gpg->colon.buffer = _gpgme_malloc (gpg->colon.bufsize);
if (!gpg->colon.buffer) if (!gpg->colon.buffer)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1) if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (gpg->colon.buffer); _gpgme_free (gpg->colon.buffer);
gpg->colon.buffer = NULL; gpg->colon.buffer = NULL;
return saved_err; return saved_err;
} }
@ -741,7 +742,7 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
return err; return err;
use_agent = (p && strchr (p, ':')); use_agent = (p && strchr (p, ':'));
if (p) if (p)
free (p); _gpgme_free (p);
} }
if (gpg->argv) if (gpg->argv)
@ -781,10 +782,10 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
argc++; /* --batch */ argc++; /* --batch */
argc += 1; /* --no-sk-comments */ argc += 1; /* --no-sk-comments */
argv = calloc (argc + 1, sizeof *argv); argv = _gpgme_calloc (argc + 1, sizeof *argv);
if (!argv) if (!argv)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
fd_data_map = calloc (datac + 1, sizeof *fd_data_map); fd_data_map = _gpgme_calloc (datac + 1, sizeof *fd_data_map);
if (!fd_data_map) if (!fd_data_map)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
@ -793,22 +794,22 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
} }
argc = datac = 0; argc = datac = 0;
argv[argc] = strdup (_gpgme_get_basename (pgmname)); /* argv[0] */ argv[argc] = _gpgme_strdup (_gpgme_get_basename (pgmname)); /* argv[0] */
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
argc++; argc++;
if (need_special) if (need_special)
{ {
argv[argc] = strdup ("--enable-special-filenames"); argv[argc] = _gpgme_strdup ("--enable-special-filenames");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
@ -816,11 +817,11 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
} }
if (use_agent) if (use_agent)
{ {
argv[argc] = strdup ("--use-agent"); argv[argc] = _gpgme_strdup ("--use-agent");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
@ -840,11 +841,11 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
} }
if (s) if (s)
{ {
argv[argc] = strdup (s); argv[argc] = _gpgme_strdup (s);
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
@ -854,21 +855,21 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
if (!gpg->cmd.used) if (!gpg->cmd.used)
{ {
argv[argc] = strdup ("--batch"); argv[argc] = _gpgme_strdup ("--batch");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
argc++; argc++;
} }
argv[argc] = strdup ("--no-sk-comments"); argv[argc] = _gpgme_strdup ("--no-sk-comments");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
@ -891,7 +892,7 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
== -1) == -1)
{ {
int saved_errno = errno; int saved_errno = errno;
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return gpg_error (saved_errno); return gpg_error (saved_errno);
} }
@ -943,11 +944,11 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
char *ptr; char *ptr;
int buflen = 25; int buflen = 25;
argv[argc] = malloc (buflen); argv[argc] = _gpgme_malloc (buflen);
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
@ -968,11 +969,11 @@ build_argv (engine_gpg_t gpg, const char *pgmname)
} }
else else
{ {
argv[argc] = strdup (a->arg); argv[argc] = _gpgme_strdup (a->arg);
if (!argv[argc]) if (!argv[argc])
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_data_map); _gpgme_free (fd_data_map);
free_argv (argv); free_argv (argv);
return saved_err; return saved_err;
} }
@ -1023,7 +1024,7 @@ read_status (engine_gpg_t gpg)
{ {
/* Need more room for the read. */ /* Need more room for the read. */
bufsize += 1024; bufsize += 1024;
buffer = realloc (buffer, bufsize); buffer = _gpgme_realloc (buffer, bufsize);
if (!buffer) if (!buffer)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -1078,8 +1079,8 @@ read_status (engine_gpg_t gpg)
{ {
gpg->cmd.code = r; gpg->cmd.code = r;
if (gpg->cmd.keyword) if (gpg->cmd.keyword)
free (gpg->cmd.keyword); _gpgme_free (gpg->cmd.keyword);
gpg->cmd.keyword = strdup (rest); gpg->cmd.keyword = _gpgme_strdup (rest);
if (!gpg->cmd.keyword) if (!gpg->cmd.keyword)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
/* This should be the last thing we have /* This should be the last thing we have
@ -1199,7 +1200,7 @@ read_colon_line (engine_gpg_t gpg)
{ {
/* Need more room for the read. */ /* Need more room for the read. */
bufsize += 1024; bufsize += 1024;
buffer = realloc (buffer, bufsize); buffer = _gpgme_realloc (buffer, bufsize);
if (!buffer) if (!buffer)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -1257,7 +1258,7 @@ read_colon_line (engine_gpg_t gpg)
} }
while (linep && *linep); while (linep && *linep);
free (line); _gpgme_free (line);
} }
else else
gpg->colon.fnc (gpg->colon.fnc_value, buffer); gpg->colon.fnc (gpg->colon.fnc_value, buffer);
@ -1352,7 +1353,7 @@ start (engine_gpg_t gpg)
n = 3; n = 3;
for (i = 0; gpg->fd_data_map[i].data; i++) for (i = 0; gpg->fd_data_map[i].data; i++)
n++; n++;
fd_list = calloc (n, sizeof *fd_list); fd_list = _gpgme_calloc (n, sizeof *fd_list);
if (! fd_list) if (! fd_list)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -1383,7 +1384,7 @@ start (engine_gpg_t gpg)
fd_list, NULL, NULL, &pid); fd_list, NULL, NULL, &pid);
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fd_list); _gpgme_free (fd_list);
if (status == -1) if (status == -1)
return saved_err; return saved_err;
} }
@ -1548,7 +1549,7 @@ append_args_from_sig_notations (engine_gpg_t gpg, gpgme_ctx_t ctx /* FIXME */)
the name, one byte for '=', the value, and a terminating the name, one byte for '=', the value, and a terminating
'\0'. */ '\0'. */
arg = malloc (1 + notation->name_len + 1 + notation->value_len + 1); arg = _gpgme_malloc (1 + notation->name_len + 1 + notation->value_len + 1);
if (!arg) if (!arg)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -1574,7 +1575,7 @@ append_args_from_sig_notations (engine_gpg_t gpg, gpgme_ctx_t ctx /* FIXME */)
err = add_arg (gpg, arg); err = add_arg (gpg, arg);
if (arg) if (arg)
free (arg); _gpgme_free (arg);
} }
else else
{ {
@ -1584,7 +1585,7 @@ append_args_from_sig_notations (engine_gpg_t gpg, gpgme_ctx_t ctx /* FIXME */)
if (notation->critical) if (notation->critical)
{ {
value = malloc (1 + notation->value_len + 1); value = _gpgme_malloc (1 + notation->value_len + 1);
if (!value) if (!value)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
@ -1603,7 +1604,7 @@ append_args_from_sig_notations (engine_gpg_t gpg, gpgme_ctx_t ctx /* FIXME */)
err = add_arg (gpg, value); err = add_arg (gpg, value);
if (value != notation->value) if (value != notation->value)
free (value); _gpgme_free (value);
} }
notation = notation->next; notation = notation->next;
@ -1921,7 +1922,7 @@ string_from_data (gpgme_data_t data, int delim,
{ {
if (*helpptr) if (*helpptr)
{ {
free (*helpptr); _gpgme_free (*helpptr);
*helpptr = NULL; *helpptr = NULL;
} }
return NULL; return NULL;
@ -1931,7 +1932,7 @@ string_from_data (gpgme_data_t data, int delim,
self = *helpptr; self = *helpptr;
else else
{ {
self = malloc (sizeof *self); self = _gpgme_malloc (sizeof *self);
if (!self) if (!self)
{ {
*r_err = gpg_error_from_syserror (); *r_err = gpg_error_from_syserror ();
@ -2135,7 +2136,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
n = strlen (field[1]); n = strlen (field[1]);
if (n > 16) if (n > 16)
{ {
if (asprintf (r_line, if (_gpgme_asprintf (r_line,
"pub:o%s:%s:%s:%s:%s:%s::::::::\n" "pub:o%s:%s:%s:%s:%s:%s::::::::\n"
"fpr:::::::::%s:", "fpr:::::::::%s:",
field[6], field[3], field[2], field[1] + n - 16, field[6], field[3], field[2], field[1] + n - 16,
@ -2144,7 +2145,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
} }
else else
{ {
if (asprintf (r_line, if (_gpgme_asprintf (r_line,
"pub:o%s:%s:%s:%s:%s:%s::::::::", "pub:o%s:%s:%s:%s:%s:%s::::::::",
field[6], field[3], field[2], field[1], field[6], field[3], field[2], field[1],
field[4], field[5]) < 0) field[4], field[5]) < 0)
@ -2170,7 +2171,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
Because we have to replace each '%HL' by '\xHL', we need at Because we have to replace each '%HL' by '\xHL', we need at
most 4/3 th the number of bytes. But because we also need most 4/3 th the number of bytes. But because we also need
to escape the backslashes we allocate twice as much. */ to escape the backslashes we allocate twice as much. */
char *uid = malloc (2 * strlen (field[1]) + 1); char *uid = _gpgme_malloc (2 * strlen (field[1]) + 1);
char *src; char *src;
char *dst; char *dst;
@ -2201,7 +2202,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
} }
*dst = '\0'; *dst = '\0';
if (asprintf (r_line, "uid:o%s::::%s:%s:::%s:", if (_gpgme_asprintf (r_line, "uid:o%s::::%s:%s:::%s:",
field[4], field[2], field[3], uid) < 0) field[4], field[2], field[3], uid) < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }

View File

@ -46,6 +46,7 @@
#include "debug.h" #include "debug.h"
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
struct engine_gpgconf struct engine_gpgconf
@ -81,11 +82,11 @@ gpgconf_release (void *engine)
return; return;
if (gpgconf->file_name) if (gpgconf->file_name)
free (gpgconf->file_name); _gpgme_free (gpgconf->file_name);
if (gpgconf->home_dir) 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; gpgme_error_t err = 0;
engine_gpgconf_t gpgconf; engine_gpgconf_t gpgconf;
gpgconf = calloc (1, sizeof *gpgconf); gpgconf = _gpgme_calloc (1, sizeof *gpgconf);
if (!gpgconf) if (!gpgconf)
return gpg_error_from_syserror (); 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 ()); : _gpgme_get_default_gpgconf_name ());
if (!gpgconf->file_name) if (!gpgconf->file_name)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
if (!err && home_dir) if (!err && home_dir)
{ {
gpgconf->home_dir = strdup (home_dir); gpgconf->home_dir = _gpgme_strdup (home_dir);
if (!gpgconf->home_dir) if (!gpgconf->home_dir)
err = gpg_error_from_syserror (); 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; gpgme_conf_arg_t next = arg->next;
if (alt_type == GPGME_CONF_STRING) if (alt_type == GPGME_CONF_STRING)
free (arg->value.string); _gpgme_free (arg->value.string);
free (arg); _gpgme_free (arg);
arg = next; arg = next;
} }
} }
@ -139,21 +140,21 @@ static void
release_opt (gpgme_conf_opt_t opt) release_opt (gpgme_conf_opt_t opt)
{ {
if (opt->name) if (opt->name)
free (opt->name); _gpgme_free (opt->name);
if (opt->description) if (opt->description)
free (opt->description); _gpgme_free (opt->description);
if (opt->argname) if (opt->argname)
free (opt->argname); _gpgme_free (opt->argname);
release_arg (opt->default_value, opt->alt_type); release_arg (opt->default_value, opt->alt_type);
if (opt->default_description) 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->no_arg_value, opt->alt_type);
release_arg (opt->value, opt->alt_type); release_arg (opt->value, opt->alt_type);
release_arg (opt->new_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; gpgme_conf_opt_t opt;
if (comp->name) if (comp->name)
free (comp->name); _gpgme_free (comp->name);
if (comp->description) if (comp->description)
free (comp->description); _gpgme_free (comp->description);
if (comp->program_name) if (comp->program_name)
free (comp->program_name); _gpgme_free (comp->program_name);
opt = comp->options; opt = comp->options;
while (opt) while (opt)
@ -177,7 +178,7 @@ release_comp (gpgme_conf_comp_t comp)
opt = next; 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. */ linebufsize = 1024; /* Usually enough for conf lines. */
linebuf = malloc (linebufsize); linebuf = _gpgme_malloc (linebufsize);
if (!linebuf) if (!linebuf)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -298,7 +299,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2,
goto leave; goto leave;
} }
newlinebuf = realloc (linebuf, linebufsize); newlinebuf = _gpgme_realloc (linebuf, linebufsize);
if (!newlinebuf) if (!newlinebuf)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -309,7 +310,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2,
} }
leave: leave:
free (linebuf); _gpgme_free (linebuf);
_gpgme_io_close (rp[0]); _gpgme_io_close (rp[0]);
return err; return err;
} }
@ -342,24 +343,24 @@ gpgconf_config_load_cb (void *hook, char *line)
if (comp) if (comp)
comp_p = &comp->next; comp_p = &comp->next;
comp = calloc (1, sizeof (*comp)); comp = _gpgme_calloc (1, sizeof (*comp));
if (!comp) if (!comp)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
/* Prepare return value. */ /* Prepare return value. */
comp->_last_opt_p = &comp->options; comp->_last_opt_p = &comp->options;
*comp_p = comp; *comp_p = comp;
comp->name = strdup (field[0]); comp->name = _gpgme_strdup (field[0]);
if (!comp->name) if (!comp->name)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
comp->description = strdup (field[1]); comp->description = _gpgme_strdup (field[1]);
if (!comp->description) if (!comp->description)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
if (fields >= 3) if (fields >= 3)
{ {
comp->program_name = strdup (field[2]); comp->program_name = _gpgme_strdup (field[2]);
if (!comp->program_name) if (!comp->program_name)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -386,7 +387,7 @@ gpgconf_parse_option (gpgme_conf_opt_t opt,
if (mark) if (mark)
*mark = '\0'; *mark = '\0';
arg = calloc (1, sizeof (*arg)); arg = _gpgme_calloc (1, sizeof (*arg));
if (!arg) if (!arg)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
*arg_p = arg; *arg_p = arg;
@ -462,7 +463,7 @@ gpgconf_config_load_cb2 (void *hook, char *line)
if (fields < 10) if (fields < 10)
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
opt = calloc (1, sizeof (*opt)); opt = _gpgme_calloc (1, sizeof (*opt));
if (!opt) if (!opt)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -471,7 +472,7 @@ gpgconf_config_load_cb2 (void *hook, char *line)
if (field[0][0]) if (field[0][0])
{ {
opt->name = strdup (field[0]); opt->name = _gpgme_strdup (field[0]);
if (!opt->name) if (!opt->name)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -482,7 +483,7 @@ gpgconf_config_load_cb2 (void *hook, char *line)
if (field[3][0]) if (field[3][0])
{ {
opt->description = strdup (field[3]); opt->description = _gpgme_strdup (field[3]);
if (!opt->description) if (!opt->description)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -493,7 +494,7 @@ gpgconf_config_load_cb2 (void *hook, char *line)
if (field[6][0]) if (field[6][0])
{ {
opt->argname = strdup (field[6]); opt->argname = _gpgme_strdup (field[6]);
if (!opt->argname) if (!opt->argname)
return gpg_error_from_syserror (); 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]) 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) if (!opt->default_description)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
if (opt->flags & GPGME_CONF_NO_ARG_DESC) 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) if (!opt->no_arg_description)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -575,7 +576,7 @@ _gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p,
{ {
gpgme_conf_arg_t arg; gpgme_conf_arg_t arg;
arg = calloc (1, sizeof (*arg)); arg = _gpgme_calloc (1, sizeof (*arg));
if (!arg) if (!arg)
return gpg_error_from_syserror (); 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_PUB_KEY:
case GPGME_CONF_SEC_KEY: case GPGME_CONF_SEC_KEY:
case GPGME_CONF_ALIAS_LIST: case GPGME_CONF_ALIAS_LIST:
arg->value.string = strdup (value); arg->value.string = _gpgme_strdup (value);
if (!arg->value.string) if (!arg->value.string)
{ {
free (arg); _gpgme_free (arg);
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
break; break;
default: default:
free (arg); _gpgme_free (arg);
return gpg_error (GPG_ERR_INV_VALUE); return gpg_error (GPG_ERR_INV_VALUE);
} }
} }

View File

@ -51,6 +51,7 @@
#include "debug.h" #include "debug.h"
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
typedef struct typedef struct
@ -157,7 +158,7 @@ close_notify_handler (int fd, void *opaque)
} }
if (gpgsm->input_helper_memory) if (gpgsm->input_helper_memory)
{ {
free (gpgsm->input_helper_memory); _gpgme_free (gpgsm->input_helper_memory);
gpgsm->input_helper_memory = NULL; gpgsm->input_helper_memory = NULL;
} }
} }
@ -229,8 +230,8 @@ gpgsm_release (void *engine)
gpgsm_cancel (engine); gpgsm_cancel (engine);
free (gpgsm->colon.attic.line); _gpgme_free (gpgsm->colon.attic.line);
free (gpgsm); _gpgme_free (gpgsm);
} }
@ -251,7 +252,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
char *dft_ttytype = NULL; char *dft_ttytype = NULL;
char *optstr; char *optstr;
gpgsm = calloc (1, sizeof *gpgsm); gpgsm = _gpgme_calloc (1, sizeof *gpgsm);
if (!gpgsm) if (!gpgsm)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -388,17 +389,17 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_display) if (dft_display)
{ {
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0) if (_gpgme_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{ {
free (dft_display); _gpgme_free (dft_display);
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
free (dft_display); _gpgme_free (dft_display);
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -415,14 +416,14 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
} }
else else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
@ -431,17 +432,17 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_ttytype) if (dft_ttytype)
{ {
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{ {
free (dft_ttytype); _gpgme_free (dft_ttytype);
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
free (dft_ttytype); _gpgme_free (dft_ttytype);
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -546,13 +547,13 @@ gpgsm_set_locale (void *engine, int category, const char *value)
if (!value) if (!value)
return 0; return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0) if (_gpgme_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
{ {
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
} }
return err; return err;
@ -830,7 +831,7 @@ status_handler (void *opaque, int fd)
if (gpgsm->colon.attic.linesize < *alinelen + linelen + 1) if (gpgsm->colon.attic.linesize < *alinelen + linelen + 1)
{ {
char *newline = realloc (*aline, *alinelen + linelen + 1); char *newline = _gpgme_realloc (*aline, *alinelen + linelen + 1);
if (!newline) if (!newline)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
@ -1118,7 +1119,7 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret)
} }
length++; length++;
line = malloc (length); line = _gpgme_malloc (length);
if (!line) if (!line)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -1158,7 +1159,7 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret)
gpgsm->inline_data = NULL; gpgsm->inline_data = NULL;
err = start (gpgsm, line); err = start (gpgsm, line);
free (line); _gpgme_free (line);
return err; return err;
} }
@ -1175,7 +1176,7 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
int i; int i;
linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */
line = malloc (10 + 40 + 1); line = _gpgme_malloc (10 + 40 + 1);
if (!line) if (!line)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
strcpy (line, "RECIPIENT "); strcpy (line, "RECIPIENT ");
@ -1194,11 +1195,11 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
newlen = 11 + strlen (fpr); newlen = 11 + strlen (fpr);
if (linelen < newlen) if (linelen < newlen)
{ {
char *newline = realloc (line, newlen); char *newline = _gpgme_realloc (line, newlen);
if (! newline) if (! newline)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (line); _gpgme_free (line);
return saved_err; return saved_err;
} }
line = newline; line = newline;
@ -1213,11 +1214,11 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
invalid_recipients++; invalid_recipients++;
else if (err) else if (err)
{ {
free (line); _gpgme_free (line);
return err; return err;
} }
} }
free (line); _gpgme_free (line);
return gpg_error (invalid_recipients return gpg_error (invalid_recipients
? GPG_ERR_UNUSABLE_PUBKEY : GPG_ERR_NO_ERROR); ? GPG_ERR_UNUSABLE_PUBKEY : GPG_ERR_NO_ERROR);
} }
@ -1281,7 +1282,7 @@ gpgsm_export (void *engine, const char *pattern, gpgme_export_mode_t mode,
if (!pattern) if (!pattern)
pattern = ""; pattern = "";
cmd = malloc (7 + strlen (pattern) + 1); cmd = _gpgme_malloc (7 + strlen (pattern) + 1);
if (!cmd) if (!cmd)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
strcpy (cmd, "EXPORT "); strcpy (cmd, "EXPORT ");
@ -1297,7 +1298,7 @@ gpgsm_export (void *engine, const char *pattern, gpgme_export_mode_t mode,
gpgsm->inline_data = NULL; gpgsm->inline_data = NULL;
err = start (gpgsm, cmd); err = start (gpgsm, cmd);
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
@ -1338,7 +1339,7 @@ gpgsm_export_ext (void *engine, const char *pattern[], gpgme_export_mode_t mode,
length++; length++;
} }
} }
line = malloc (length); line = _gpgme_malloc (length);
if (!line) if (!line)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -1393,7 +1394,7 @@ gpgsm_export_ext (void *engine, const char *pattern[], gpgme_export_mode_t mode,
gpgsm->inline_data = NULL; gpgsm->inline_data = NULL;
err = start (gpgsm, line); err = start (gpgsm, line);
free (line); _gpgme_free (line);
return err; return err;
} }
@ -1468,7 +1469,7 @@ gpgsm_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray)
} }
/* Allocate a bufer with extra space for the trailing Nul /* Allocate a bufer with extra space for the trailing Nul
introduced by the use of stpcpy. */ introduced by the use of stpcpy. */
buffer = malloc (buflen+1); buffer = _gpgme_malloc (buflen+1);
if (!buffer) if (!buffer)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
for (idx=0, p = buffer; keyarray[idx]; idx++) for (idx=0, p = buffer; keyarray[idx]; idx++)
@ -1484,7 +1485,7 @@ gpgsm_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray)
buffer, buflen, 0); buffer, buflen, 0);
if (err) if (err)
{ {
free (buffer); _gpgme_free (buffer);
return err; return err;
} }
gpgsm->input_helper_memory = buffer; gpgsm->input_helper_memory = buffer;
@ -1495,7 +1496,7 @@ gpgsm_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray)
{ {
gpgme_data_release (gpgsm->input_helper_data); gpgme_data_release (gpgsm->input_helper_data);
gpgsm->input_helper_data = NULL; gpgsm->input_helper_data = NULL;
free (gpgsm->input_helper_memory); _gpgme_free (gpgsm->input_helper_memory);
gpgsm->input_helper_memory = NULL; gpgsm->input_helper_memory = NULL;
return err; return err;
} }
@ -1556,10 +1557,10 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
NULL, NULL); NULL, NULL);
/* Always send list-mode option because RESET does not reset it. */ /* Always send list-mode option because RESET does not reset it. */
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0) if (_gpgme_asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL);
free (line); _gpgme_free (line);
if (err) if (err)
return err; return err;
@ -1588,7 +1589,7 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
/* Length is "LISTSECRETKEYS " + p + '\0'. */ /* Length is "LISTSECRETKEYS " + p + '\0'. */
line = malloc (15 + strlen (pattern) + 1); line = _gpgme_malloc (15 + strlen (pattern) + 1);
if (!line) if (!line)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
if (secret_only) if (secret_only)
@ -1608,7 +1609,7 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
gpgsm->inline_data = NULL; gpgsm->inline_data = NULL;
err = start (gpgsm, line); err = start (gpgsm, line);
free (line); _gpgme_free (line);
return err; return err;
} }
@ -1635,10 +1636,10 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
list_mode |= 2; list_mode |= 2;
/* Always send list-mode option because RESET does not reset it. */ /* Always send list-mode option because RESET does not reset it. */
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0) if (_gpgme_asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL);
free (line); _gpgme_free (line);
if (err) if (err)
return err; return err;
@ -1676,7 +1677,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
length++; length++;
} }
} }
line = malloc (length); line = _gpgme_malloc (length);
if (!line) if (!line)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
if (secret_only) if (secret_only)
@ -1736,7 +1737,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
gpgsm->inline_data = NULL; gpgsm->inline_data = NULL;
err = start (gpgsm, line); err = start (gpgsm, line);
free (line); _gpgme_free (line);
return err; return err;
} }
@ -1763,11 +1764,11 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
can reset any previously set value in case the default is can reset any previously set value in case the default is
requested. */ requested. */
if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0) if (_gpgme_asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd, err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd,
NULL, NULL); NULL, NULL);
free (assuan_cmd); _gpgme_free (assuan_cmd);
if (err) if (err)
return err; return err;
} }
@ -1937,7 +1938,7 @@ gpgsm_passwd (void *engine, gpgme_key_t key, unsigned int flags)
if (!key || !key->subkeys || !key->subkeys->fpr) if (!key || !key->subkeys || !key->subkeys->fpr)
return gpg_error (GPG_ERR_INV_CERT_OBJ); return gpg_error (GPG_ERR_INV_CERT_OBJ);
if (asprintf (&line, "PASSWD -- %s", key->subkeys->fpr) < 0) if (_gpgme_asprintf (&line, "PASSWD -- %s", key->subkeys->fpr) < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
gpgsm_clear_fd (gpgsm, OUTPUT_FD); gpgsm_clear_fd (gpgsm, OUTPUT_FD);
@ -1946,7 +1947,7 @@ gpgsm_passwd (void *engine, gpgme_key_t key, unsigned int flags)
gpgsm->inline_data = NULL; gpgsm->inline_data = NULL;
err = start (gpgsm, line); err = start (gpgsm, line);
free (line); _gpgme_free (line);
return err; return err;
} }

View File

@ -42,6 +42,7 @@
#include "debug.h" #include "debug.h"
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
/* This type is used to build a list of data sources/sinks. */ /* This type is used to build a list of data sources/sinks. */
@ -120,7 +121,7 @@ add_data (engine_spawn_t esp, gpgme_data_t data, int dup_to, int inbound)
assert (esp); assert (esp);
assert (data); assert (data);
a = malloc (sizeof *a - 1); a = _gpgme_malloc (sizeof *a - 1);
if (!a) if (!a)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
a->next = NULL; a->next = NULL;
@ -149,7 +150,7 @@ free_fd_data_map (struct fd_data_map_s *fd_data_map)
_gpgme_io_close (fd_data_map[i].peer_fd); _gpgme_io_close (fd_data_map[i].peer_fd);
/* Don't release data because this is only a reference. */ /* Don't release data because this is only a reference. */
} }
free (fd_data_map); _gpgme_free (fd_data_map);
} }
@ -165,7 +166,7 @@ build_fd_data_map (engine_spawn_t esp)
datac++; datac++;
free_fd_data_map (esp->fd_data_map); free_fd_data_map (esp->fd_data_map);
esp->fd_data_map = calloc (datac + 1, sizeof *esp->fd_data_map); esp->fd_data_map = _gpgme_calloc (datac + 1, sizeof *esp->fd_data_map);
if (!esp->fd_data_map) if (!esp->fd_data_map)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -175,7 +176,7 @@ build_fd_data_map (engine_spawn_t esp)
if (_gpgme_io_pipe (fds, a->inbound ? 1 : 0) == -1) if (_gpgme_io_pipe (fds, a->inbound ? 1 : 0) == -1)
{ {
free (esp->fd_data_map); _gpgme_free (esp->fd_data_map);
esp->fd_data_map = NULL; esp->fd_data_map = NULL;
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -250,7 +251,7 @@ engspawn_start (engine_spawn_t esp, const char *file, const char *argv[],
n = 0; n = 0;
for (i = 0; esp->fd_data_map[i].data; i++) for (i = 0; esp->fd_data_map[i].data; i++)
n++; n++;
fd_list = calloc (n+1, sizeof *fd_list); fd_list = _gpgme_calloc (n+1, sizeof *fd_list);
if (!fd_list) if (!fd_list)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -274,7 +275,7 @@ engspawn_start (engine_spawn_t esp, const char *file, const char *argv[],
fd_list, NULL, NULL, &pid); fd_list, NULL, NULL, &pid);
if (save_argv0) if (save_argv0)
argv[0] = save_argv0; argv[0] = save_argv0;
free (fd_list); _gpgme_free (fd_list);
if (status == -1) if (status == -1)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -312,7 +313,7 @@ static char *
engspawn_get_version (const char *file_name) engspawn_get_version (const char *file_name)
{ {
(void)file_name; (void)file_name;
return strdup ("1.0"); return _gpgme_strdup ("1.0");
} }
@ -331,7 +332,7 @@ engspawn_new (void **engine, const char *file_name, const char *home_dir)
(void)file_name; (void)file_name;
(void)home_dir; (void)home_dir;
esp = calloc (1, sizeof *esp); esp = _gpgme_calloc (1, sizeof *esp);
if (!esp) if (!esp)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -356,11 +357,11 @@ engspawn_release (void *engine)
struct datalist_s *next = esp->arglist->next; struct datalist_s *next = esp->arglist->next;
if (esp->arglist) if (esp->arglist)
free (esp->arglist); _gpgme_free (esp->arglist);
esp->arglist = next; esp->arglist = next;
} }
free (esp); _gpgme_free (esp);
} }

View File

@ -52,6 +52,7 @@
#include "debug.h" #include "debug.h"
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
typedef struct typedef struct
@ -121,7 +122,7 @@ static void uiserver_io_event (void *engine,
static char * static char *
uiserver_get_version (const char *file_name) uiserver_get_version (const char *file_name)
{ {
return strdup ("1.0"); return _gpgme_strdup ("1.0");
} }
@ -158,7 +159,7 @@ close_notify_handler (int fd, void *opaque)
} }
if (uiserver->input_helper_memory) if (uiserver->input_helper_memory)
{ {
free (uiserver->input_helper_memory); _gpgme_free (uiserver->input_helper_memory);
uiserver->input_helper_memory = NULL; uiserver->input_helper_memory = NULL;
} }
} }
@ -230,8 +231,8 @@ uiserver_release (void *engine)
uiserver_cancel (engine); uiserver_cancel (engine);
free (uiserver->colon.attic.line); _gpgme_free (uiserver->colon.attic.line);
free (uiserver); _gpgme_free (uiserver);
} }
@ -245,7 +246,7 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
char *dft_ttytype = NULL; char *dft_ttytype = NULL;
char *optstr; char *optstr;
uiserver = calloc (1, sizeof *uiserver); uiserver = _gpgme_calloc (1, sizeof *uiserver);
if (!uiserver) if (!uiserver)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -306,17 +307,17 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_display) if (dft_display)
{ {
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0) if (_gpgme_asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (dft_display); _gpgme_free (dft_display);
goto leave; goto leave;
} }
free (dft_display); _gpgme_free (dft_display);
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -333,14 +334,14 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
} }
else else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
@ -349,17 +350,17 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
goto leave; goto leave;
if (dft_ttytype) if (dft_ttytype)
{ {
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0) if (_gpgme_asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (dft_ttytype); _gpgme_free (dft_ttytype);
goto leave; goto leave;
} }
free (dft_ttytype); _gpgme_free (dft_ttytype);
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
if (err) if (err)
goto leave; goto leave;
} }
@ -424,13 +425,13 @@ uiserver_set_locale (void *engine, int category, const char *value)
if (!value) if (!value)
return 0; return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0) if (_gpgme_asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
{ {
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
free (optstr); _gpgme_free (optstr);
} }
return err; return err;
@ -692,7 +693,7 @@ status_handler (void *opaque, int fd)
if (uiserver->colon.attic.linesize < *alinelen + linelen + 1) if (uiserver->colon.attic.linesize < *alinelen + linelen + 1)
{ {
char *newline = realloc (*aline, *alinelen + linelen + 1); char *newline = _gpgme_realloc (*aline, *alinelen + linelen + 1);
if (!newline) if (!newline)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
@ -941,7 +942,7 @@ _uiserver_decrypt (void *engine, int verify,
else else
return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL); return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
if (asprintf (&cmd, "DECRYPT%s%s", protocol, if (_gpgme_asprintf (&cmd, "DECRYPT%s%s", protocol,
verify ? "" : " --no-verify") < 0) verify ? "" : " --no-verify") < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -950,20 +951,20 @@ _uiserver_decrypt (void *engine, int verify,
map_data_enc (uiserver->input_cb.data)); map_data_enc (uiserver->input_cb.data));
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return gpg_error (GPG_ERR_GENERAL); /* FIXME */ return gpg_error (GPG_ERR_GENERAL); /* FIXME */
} }
uiserver->output_cb.data = plain; uiserver->output_cb.data = plain;
err = uiserver_set_fd (uiserver, OUTPUT_FD, 0); err = uiserver_set_fd (uiserver, OUTPUT_FD, 0);
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return gpg_error (GPG_ERR_GENERAL); /* FIXME */ return gpg_error (GPG_ERR_GENERAL); /* FIXME */
} }
uiserver->inline_data = NULL; uiserver->inline_data = NULL;
err = start (engine, cmd); err = start (engine, cmd);
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
@ -993,7 +994,7 @@ set_recipients (engine_uiserver_t uiserver, gpgme_key_t recp[])
int i; int i;
linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */
line = malloc (10 + 40 + 1); line = _gpgme_malloc (10 + 40 + 1);
if (!line) if (!line)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
strcpy (line, "RECIPIENT "); strcpy (line, "RECIPIENT ");
@ -1012,11 +1013,11 @@ set_recipients (engine_uiserver_t uiserver, gpgme_key_t recp[])
newlen = 11 + strlen (uid); newlen = 11 + strlen (uid);
if (linelen < newlen) if (linelen < newlen)
{ {
char *newline = realloc (line, newlen); char *newline = _gpgme_realloc (line, newlen);
if (! newline) if (! newline)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (line); _gpgme_free (line);
return saved_err; return saved_err;
} }
line = newline; line = newline;
@ -1032,11 +1033,11 @@ set_recipients (engine_uiserver_t uiserver, gpgme_key_t recp[])
invalid_recipients++; invalid_recipients++;
else if (err) else if (err)
{ {
free (line); _gpgme_free (line);
return err; return err;
} }
} }
free (line); _gpgme_free (line);
return gpg_error (invalid_recipients return gpg_error (invalid_recipients
? GPG_ERR_UNUSABLE_PUBKEY : GPG_ERR_NO_ERROR); ? GPG_ERR_UNUSABLE_PUBKEY : GPG_ERR_NO_ERROR);
} }
@ -1067,7 +1068,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
if (!recp || plain || ciph) if (!recp || plain || ciph)
return gpg_error (GPG_ERR_INV_VALUE); return gpg_error (GPG_ERR_INV_VALUE);
if (asprintf (&cmd, "PREP_ENCRYPT%s%s", protocol, if (_gpgme_asprintf (&cmd, "PREP_ENCRYPT%s%s", protocol,
(flags & GPGME_ENCRYPT_EXPECT_SIGN) (flags & GPGME_ENCRYPT_EXPECT_SIGN)
? " --expect-sign" : "") < 0) ? " --expect-sign" : "") < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -1077,7 +1078,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
if (!plain || !ciph) if (!plain || !ciph)
return gpg_error (GPG_ERR_INV_VALUE); return gpg_error (GPG_ERR_INV_VALUE);
if (asprintf (&cmd, "ENCRYPT%s", protocol) < 0) if (_gpgme_asprintf (&cmd, "ENCRYPT%s", protocol) < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -1088,7 +1089,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
map_data_enc (uiserver->input_cb.data)); map_data_enc (uiserver->input_cb.data));
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
} }
@ -1100,7 +1101,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
: map_data_enc (uiserver->output_cb.data)); : map_data_enc (uiserver->output_cb.data));
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
} }
@ -1112,13 +1113,13 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
err = set_recipients (uiserver, recp); err = set_recipients (uiserver, recp);
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
} }
err = start (uiserver, cmd); err = start (uiserver, cmd);
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
@ -1145,7 +1146,7 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
else else
return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL); return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
if (asprintf (&cmd, "SIGN%s%s", protocol, if (_gpgme_asprintf (&cmd, "SIGN%s%s", protocol,
(mode == GPGME_SIG_MODE_DETACH) ? " --detached" : "") < 0) (mode == GPGME_SIG_MODE_DETACH) ? " --detached" : "") < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -1171,7 +1172,7 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
gpgme_key_unref (key); gpgme_key_unref (key);
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
} }
@ -1181,7 +1182,7 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
map_data_enc (uiserver->input_cb.data)); map_data_enc (uiserver->input_cb.data));
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
uiserver->output_cb.data = out; uiserver->output_cb.data = out;
@ -1189,13 +1190,13 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
: map_data_enc (uiserver->output_cb.data)); : map_data_enc (uiserver->output_cb.data));
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
uiserver->inline_data = NULL; uiserver->inline_data = NULL;
err = start (uiserver, cmd); err = start (uiserver, cmd);
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
@ -1221,7 +1222,7 @@ uiserver_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
else else
return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL); return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
if (asprintf (&cmd, "VERIFY%s", protocol) < 0) if (_gpgme_asprintf (&cmd, "VERIFY%s", protocol) < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
uiserver->input_cb.data = sig; uiserver->input_cb.data = sig;
@ -1229,7 +1230,7 @@ uiserver_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
map_data_enc (uiserver->input_cb.data)); map_data_enc (uiserver->input_cb.data));
if (err) if (err)
{ {
free (cmd); _gpgme_free (cmd);
return err; return err;
} }
if (plaintext) if (plaintext)
@ -1249,7 +1250,7 @@ uiserver_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
if (!err) if (!err)
err = start (uiserver, cmd); err = start (uiserver, cmd);
free (cmd); _gpgme_free (cmd);
return err; return err;
} }

View File

@ -34,6 +34,7 @@
#include "engine.h" #include "engine.h"
#include "engine-backend.h" #include "engine-backend.h"
#include "mem.h"
struct engine struct engine
@ -165,12 +166,12 @@ _gpgme_engine_info_release (gpgme_engine_info_t info)
gpgme_engine_info_t next_info = info->next; gpgme_engine_info_t next_info = info->next;
assert (info->file_name); assert (info->file_name);
free (info->file_name); _gpgme_free (info->file_name);
if (info->home_dir) if (info->home_dir)
free (info->home_dir); _gpgme_free (info->home_dir);
if (info->version) if (info->version)
free (info->version); _gpgme_free (info->version);
free (info); _gpgme_free (info);
info = next_info; info = next_info;
} }
} }
@ -209,20 +210,20 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
if (!ofile_name) if (!ofile_name)
continue; continue;
file_name = strdup (ofile_name); file_name = _gpgme_strdup (ofile_name);
if (!file_name) if (!file_name)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
if (ohome_dir) if (ohome_dir)
{ {
home_dir = strdup (ohome_dir); home_dir = _gpgme_strdup (ohome_dir);
if (!home_dir && !err) if (!home_dir && !err)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
} }
else else
home_dir = NULL; home_dir = NULL;
*lastp = malloc (sizeof (*engine_info)); *lastp = _gpgme_malloc (sizeof (*engine_info));
if (!*lastp && !err) if (!*lastp && !err)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -232,9 +233,9 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
engine_info = NULL; engine_info = NULL;
if (file_name) if (file_name)
free (file_name); _gpgme_free (file_name);
if (home_dir) if (home_dir)
free (home_dir); _gpgme_free (home_dir);
UNLOCK (engine_info_lock); UNLOCK (engine_info_lock);
return err; return err;
@ -288,13 +289,13 @@ _gpgme_engine_info_copy (gpgme_engine_info_t *r_info)
char *version; char *version;
assert (info->file_name); assert (info->file_name);
file_name = strdup (info->file_name); file_name = _gpgme_strdup (info->file_name);
if (!file_name) if (!file_name)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
if (info->home_dir) if (info->home_dir)
{ {
home_dir = strdup (info->home_dir); home_dir = _gpgme_strdup (info->home_dir);
if (!home_dir && !err) if (!home_dir && !err)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
} }
@ -303,14 +304,14 @@ _gpgme_engine_info_copy (gpgme_engine_info_t *r_info)
if (info->version) if (info->version)
{ {
version = strdup (info->version); version = _gpgme_strdup (info->version);
if (!version && !err) if (!version && !err)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
} }
else else
version = NULL; version = NULL;
*lastp = malloc (sizeof (*engine_info)); *lastp = _gpgme_malloc (sizeof (*engine_info));
if (!*lastp && !err) if (!*lastp && !err)
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -318,11 +319,11 @@ _gpgme_engine_info_copy (gpgme_engine_info_t *r_info)
{ {
_gpgme_engine_info_release (new_info); _gpgme_engine_info_release (new_info);
if (file_name) if (file_name)
free (file_name); _gpgme_free (file_name);
if (home_dir) if (home_dir)
free (home_dir); _gpgme_free (home_dir);
if (version) if (version)
free (version); _gpgme_free (version);
UNLOCK (engine_info_lock); UNLOCK (engine_info_lock);
return err; return err;
@ -366,22 +367,22 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
/* Prepare new members. */ /* Prepare new members. */
if (file_name) if (file_name)
new_file_name = strdup (file_name); new_file_name = _gpgme_strdup (file_name);
else else
{ {
const char *ofile_name = engine_get_file_name (proto); const char *ofile_name = engine_get_file_name (proto);
assert (ofile_name); assert (ofile_name);
new_file_name = strdup (ofile_name); new_file_name = _gpgme_strdup (ofile_name);
} }
if (!new_file_name) if (!new_file_name)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
if (home_dir) if (home_dir)
{ {
new_home_dir = strdup (home_dir); new_home_dir = _gpgme_strdup (home_dir);
if (!new_home_dir) if (!new_home_dir)
{ {
free (new_file_name); _gpgme_free (new_file_name);
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
} }
@ -390,10 +391,10 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
const char *ohome_dir = engine_get_home_dir (proto); const char *ohome_dir = engine_get_home_dir (proto);
if (ohome_dir) if (ohome_dir)
{ {
new_home_dir = strdup (ohome_dir); new_home_dir = _gpgme_strdup (ohome_dir);
if (!new_home_dir) if (!new_home_dir)
{ {
free (new_file_name); _gpgme_free (new_file_name);
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
} }
@ -403,11 +404,11 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
/* Remove the old members. */ /* Remove the old members. */
assert (info->file_name); assert (info->file_name);
free (info->file_name); _gpgme_free (info->file_name);
if (info->home_dir) if (info->home_dir)
free (info->home_dir); _gpgme_free (info->home_dir);
if (info->version) if (info->version)
free (info->version); _gpgme_free (info->version);
/* Install the new members. */ /* Install the new members. */
info->file_name = new_file_name; info->file_name = new_file_name;
@ -454,7 +455,7 @@ _gpgme_engine_new (gpgme_engine_info_t info, engine_t *r_engine)
if (!info->file_name || !info->version) if (!info->file_name || !info->version)
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
engine = calloc (1, sizeof *engine); engine = _gpgme_calloc (1, sizeof *engine);
if (!engine) if (!engine)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -466,7 +467,7 @@ _gpgme_engine_new (gpgme_engine_info_t info, engine_t *r_engine)
info->file_name, info->home_dir); info->file_name, info->home_dir);
if (err) if (err)
{ {
free (engine); _gpgme_free (engine);
return err; return err;
} }
} }
@ -499,7 +500,7 @@ _gpgme_engine_release (engine_t engine)
if (engine->ops->release) if (engine->ops->release)
(*engine->ops->release) (engine->engine); (*engine->ops->release) (engine->engine);
free (engine); _gpgme_free (engine);
} }

View File

@ -29,6 +29,7 @@
#include "debug.h" #include "debug.h"
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "mem.h"
static gpgme_error_t static gpgme_error_t
@ -222,7 +223,7 @@ export_keys_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t keys[],
if (!nkeys) if (!nkeys)
return gpg_error (GPG_ERR_NO_DATA); return gpg_error (GPG_ERR_NO_DATA);
pattern = calloc (nkeys+1, sizeof *pattern); pattern = _gpgme_calloc (nkeys+1, sizeof *pattern);
if (!pattern) if (!pattern)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -232,7 +233,7 @@ export_keys_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t keys[],
&& keys[idx]->subkeys->fpr && keys[idx]->subkeys->fpr
&& *keys[idx]->subkeys->fpr) && *keys[idx]->subkeys->fpr)
{ {
pattern[nkeys] = strdup (keys[idx]->subkeys->fpr); pattern[nkeys] = _gpgme_strdup (keys[idx]->subkeys->fpr);
if (!pattern[nkeys]) if (!pattern[nkeys])
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -248,8 +249,8 @@ export_keys_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t keys[],
leave: leave:
for (idx=0; pattern[idx]; idx++) for (idx=0; pattern[idx]; idx++)
free (pattern[idx]); _gpgme_free (pattern[idx]);
free (pattern); _gpgme_free (pattern);
return err; return err;
} }

View File

@ -31,6 +31,7 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "util.h" #include "util.h"
#include "mem.h"
typedef struct typedef struct
@ -48,7 +49,7 @@ release_op_data (void *hook)
op_data_t opd = (op_data_t) hook; op_data_t opd = (op_data_t) hook;
if (opd->result.fpr) if (opd->result.fpr)
free (opd->result.fpr); _gpgme_free (opd->result.fpr);
if (opd->key_parameter) if (opd->key_parameter)
gpgme_data_release (opd->key_parameter); gpgme_data_release (opd->key_parameter);
} }
@ -110,8 +111,8 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args)
if (args[1] == ' ') if (args[1] == ' ')
{ {
if (opd->result.fpr) if (opd->result.fpr)
free (opd->result.fpr); _gpgme_free (opd->result.fpr);
opd->result.fpr = strdup (&args[2]); opd->result.fpr = _gpgme_strdup (&args[2]);
if (!opd->result.fpr) if (!opd->result.fpr)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }

View File

@ -26,13 +26,14 @@
#include <string.h> #include <string.h>
#include "util.h" #include "util.h"
#include "mem.h"
#if defined(HAVE_THREAD_SAFE_GETENV) || !defined (HAVE_GETENV_R) #if defined(HAVE_THREAD_SAFE_GETENV) || !defined (HAVE_GETENV_R)
/* We prefer using getenv() if it is thread-safe. */ /* We prefer using getenv() if it is thread-safe. */
/* Retrieve the environment variable NAME and return a copy of it in a /* Retrieve the environment variable NAME and return a copy of it in a
malloc()'ed buffer in *VALUE. If the environment variable is not _gpgme_malloc()'ed buffer in *VALUE. If the environment variable is not
set, return NULL in *VALUE. */ set, return NULL in *VALUE. */
gpgme_error_t gpgme_error_t
_gpgme_getenv (const char *name, char **value) _gpgme_getenv (const char *name, char **value)
@ -44,7 +45,7 @@ _gpgme_getenv (const char *name, char **value)
*value = NULL; *value = NULL;
else else
{ {
*value = strdup (env_value); *value = _gpgme_strdup (env_value);
if (!*value) if (!*value)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }

View File

@ -77,7 +77,7 @@ build_commandline (char **argv)
/* And a trailing zero. */ /* And a trailing zero. */
n++; n++;
buf = p = malloc (n); buf = p = _gpgme_malloc (n);
if (!buf) if (!buf)
return NULL; return NULL;
for (i = 0; argv[i]; i++) for (i = 0; argv[i]; i++)
@ -188,7 +188,7 @@ my_spawn (char **argv, struct spawn_fd_item_s *fd_list, unsigned int flags)
NULL); NULL);
if (hnul == INVALID_HANDLE_VALUE) if (hnul == INVALID_HANDLE_VALUE)
{ {
free (arg_string); _gpgme_free (arg_string);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; errno = EIO;
return -1; return -1;
@ -217,13 +217,13 @@ my_spawn (char **argv, struct spawn_fd_item_s *fd_list, unsigned int flags)
&si, /* startup information */ &si, /* startup information */
&pi)) /* returns process information */ &pi)) /* returns process information */
{ {
free (arg_string); _gpgme_free (arg_string);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; errno = EIO;
return -1; return -1;
} }
free (arg_string); _gpgme_free (arg_string);
/* Close the /dev/nul handle if used. */ /* Close the /dev/nul handle if used. */
if (hnul != INVALID_HANDLE_VALUE) if (hnul != INVALID_HANDLE_VALUE)
@ -399,10 +399,10 @@ translate_handles (const char *trans_file, const char * const *argv,
for (idx = 0; argv[idx]; idx++) for (idx = 0; argv[idx]; idx++)
; ;
args = malloc (sizeof (*args) * (idx + 1)); args = _gpgme_malloc (sizeof (*args) * (idx + 1));
for (idx = 0; argv[idx]; idx++) for (idx = 0; argv[idx]; idx++)
{ {
args[idx] = strdup (argv[idx]); args[idx] = _gpgme_strdup (argv[idx]);
if (!args[idx]) if (!args[idx])
return NULL; return NULL;
} }
@ -424,7 +424,7 @@ translate_handles (const char *trans_file, const char * const *argv,
return NULL; return NULL;
} }
args[aidx] = malloc (sizeof (buf)); args[aidx] = _gpgme_malloc (sizeof (buf));
/* We currently disable translation for stdin/stdout/stderr. We /* We currently disable translation for stdin/stdout/stderr. We
assume that the spawned program handles 0/1/2 specially assume that the spawned program handles 0/1/2 specially
already. FIXME: Check if this is true. */ already. FIXME: Check if this is true. */

View File

@ -38,6 +38,7 @@
#include "debug.h" #include "debug.h"
#include "priv-io.h" #include "priv-io.h"
#include "sys-util.h" #include "sys-util.h"
#include "mem.h"
/* The default locale. */ /* The default locale. */
@ -52,6 +53,14 @@ gpgme_error_t _gpgme_selftest = GPG_ERR_NOT_OPERATIONAL;
accesses to a result structure are read only. */ accesses to a result structure are read only. */
DEFINE_STATIC_LOCK (result_ref_lock); 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 /* 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 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) if (!r_ctx)
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
ctx = calloc (1, sizeof *ctx); ctx = _gpgme_calloc (1, sizeof *ctx);
if (!ctx) if (!ctx)
return TRACE_ERR (gpg_error_from_syserror ()); 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); err = gpg_error (GPG_ERR_NO_ENGINE);
if (err) if (err)
{ {
free (ctx); _gpgme_free (ctx);
return TRACE_ERR (err); return TRACE_ERR (err);
} }
@ -120,13 +129,13 @@ gpgme_new (gpgme_ctx_t *r_ctx)
LOCK (def_lc_lock); LOCK (def_lc_lock);
if (def_lc_ctype) if (def_lc_ctype)
{ {
ctx->lc_ctype = strdup (def_lc_ctype); ctx->lc_ctype = _gpgme_strdup (def_lc_ctype);
if (!ctx->lc_ctype) if (!ctx->lc_ctype)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
UNLOCK (def_lc_lock); UNLOCK (def_lc_lock);
_gpgme_engine_info_release (ctx->engine_info); _gpgme_engine_info_release (ctx->engine_info);
free (ctx); _gpgme_free (ctx);
return TRACE_ERR (saved_err); return TRACE_ERR (saved_err);
} }
} }
@ -135,15 +144,15 @@ gpgme_new (gpgme_ctx_t *r_ctx)
if (def_lc_messages) if (def_lc_messages)
{ {
ctx->lc_messages = strdup (def_lc_messages); ctx->lc_messages = _gpgme_strdup (def_lc_messages);
if (!ctx->lc_messages) if (!ctx->lc_messages)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
UNLOCK (def_lc_lock); UNLOCK (def_lc_lock);
if (ctx->lc_ctype) if (ctx->lc_ctype)
free (ctx->lc_ctype); _gpgme_free (ctx->lc_ctype);
_gpgme_engine_info_release (ctx->engine_info); _gpgme_engine_info_release (ctx->engine_info);
free (ctx); _gpgme_free (ctx);
return TRACE_ERR (saved_err); return TRACE_ERR (saved_err);
} }
} }
@ -239,15 +248,15 @@ gpgme_release (gpgme_ctx_t ctx)
_gpgme_signers_clear (ctx); _gpgme_signers_clear (ctx);
_gpgme_sig_notation_clear (ctx); _gpgme_sig_notation_clear (ctx);
if (ctx->signers) if (ctx->signers)
free (ctx->signers); _gpgme_free (ctx->signers);
if (ctx->lc_ctype) if (ctx->lc_ctype)
free (ctx->lc_ctype); _gpgme_free (ctx->lc_ctype);
if (ctx->lc_messages) if (ctx->lc_messages)
free (ctx->lc_messages); _gpgme_free (ctx->lc_messages);
_gpgme_engine_info_release (ctx->engine_info); _gpgme_engine_info_release (ctx->engine_info);
ctx->engine_info = NULL; ctx->engine_info = NULL;
DESTROY_LOCK (ctx->lock); DESTROY_LOCK (ctx->lock);
free (ctx); _gpgme_free (ctx);
} }
@ -291,7 +300,7 @@ gpgme_result_unref (void *result)
if (data->cleanup) if (data->cleanup)
(*data->cleanup) (data->hook); (*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 \ if (!failed && value \
&& (category == LC_ALL || category == LC_ ## ucat)) \ && (category == LC_ALL || category == LC_ ## ucat)) \
{ \ { \
new_lc_ ## lcat = strdup (value); \ new_lc_ ## lcat = _gpgme_strdup (value); \
if (!new_lc_ ## lcat) \ if (!new_lc_ ## lcat) \
failed = 1; \ 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 (); int saved_err = gpg_error_from_syserror ();
if (new_lc_ctype) if (new_lc_ctype)
free (new_lc_ctype); _gpgme_free (new_lc_ctype);
if (new_lc_messages) if (new_lc_messages)
free (new_lc_messages); _gpgme_free (new_lc_messages);
return TRACE_ERR (saved_err); 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) \
{ \ { \
if (ctx->lc_ ## lcat) \ if (ctx->lc_ ## lcat) \
free (ctx->lc_ ## lcat); \ _gpgme_free (ctx->lc_ ## lcat); \
ctx->lc_ ## lcat = new_lc_ ## lcat; \ ctx->lc_ ## lcat = new_lc_ ## lcat; \
} \ } \
else \ else \
{ \ { \
if (def_lc_ ## lcat) \ if (def_lc_ ## lcat) \
free (def_lc_ ## lcat); \ _gpgme_free (def_lc_ ## lcat); \
def_lc_ ## lcat = new_lc_ ## lcat; \ def_lc_ ## lcat = new_lc_ ## lcat; \
} \ } \
} }

View File

@ -217,5 +217,6 @@ EXPORTS
gpgme_op_spawn_start @163 gpgme_op_spawn_start @163
gpgme_op_spawn @164 gpgme_op_spawn @164
gpgme_set_global_malloc_hooks @165
; END ; END

View File

@ -92,6 +92,14 @@ extern "C" {
#endif #endif
#endif #endif
struct gpgme_malloc_hooks
{
void *(*malloc) (size_t cnt);
void *(*calloc) (size_t nmemb, size_t cnt);
void *(*realloc) (void *ptr, size_t cnt);
void (*free) (void *ptr);
};
typedef struct gpgme_malloc_hooks *gpgme_malloc_hooks_t;
/* Some opaque data types used by GPGME. */ /* Some opaque data types used by GPGME. */
@ -196,6 +204,9 @@ gpgme_error_from_syserror (void)
return gpgme_error (gpgme_err_code_from_syserror ()); return gpgme_error (gpgme_err_code_from_syserror ());
} }
/* Set the default malloc hooks. */
void gpgme_set_global_malloc_hooks (gpgme_malloc_hooks_t malloc_hooks);
/* The possible encoding mode of gpgme_data_t objects. */ /* The possible encoding mode of gpgme_data_t objects. */
typedef enum typedef enum

View File

@ -31,6 +31,7 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "util.h" #include "util.h"
#include "mem.h"
typedef struct typedef struct
@ -53,8 +54,8 @@ release_op_data (void *hook)
while (import) while (import)
{ {
gpgme_import_status_t next = import->next; gpgme_import_status_t next = import->next;
free (import->fpr); _gpgme_free (import->fpr);
free (import); _gpgme_free (import);
import = next; import = next;
} }
} }
@ -120,7 +121,7 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
char *tail; char *tail;
long int nr; long int nr;
import = malloc (sizeof (*import)); import = _gpgme_malloc (sizeof (*import));
if (!import) if (!import)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
import->next = NULL; import->next = NULL;
@ -130,7 +131,7 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (import); _gpgme_free (import);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -171,10 +172,10 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
if (tail) if (tail)
*tail = '\0'; *tail = '\0';
import->fpr = strdup (args); import->fpr = _gpgme_strdup (args);
if (!import->fpr) if (!import->fpr)
{ {
free (import); _gpgme_free (import);
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }

View File

@ -31,6 +31,7 @@
#include "ops.h" #include "ops.h"
#include "sema.h" #include "sema.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* Protects all reference counters in keys. All other accesses to a /* Protects all reference counters in keys. All other accesses to a
@ -44,7 +45,7 @@ _gpgme_key_new (gpgme_key_t *r_key)
{ {
gpgme_key_t key; gpgme_key_t key;
key = calloc (1, sizeof *key); key = _gpgme_calloc (1, sizeof *key);
if (!key) if (!key)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
key->_refs = 1; key->_refs = 1;
@ -59,7 +60,7 @@ _gpgme_key_add_subkey (gpgme_key_t key, gpgme_subkey_t *r_subkey)
{ {
gpgme_subkey_t subkey; gpgme_subkey_t subkey;
subkey = calloc (1, sizeof *subkey); subkey = _gpgme_calloc (1, sizeof *subkey);
if (!subkey) if (!subkey)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
subkey->keyid = subkey->_keyid; subkey->keyid = subkey->_keyid;
@ -213,7 +214,7 @@ _gpgme_key_append_name (gpgme_key_t key, const char *src, int convert)
/* We can malloc a buffer of the same length, because the converted /* We can malloc a buffer of the same length, because the converted
string will never be larger. Actually we allocate it twice the string will never be larger. Actually we allocate it twice the
size, so that we are able to store the parsed stuff there too. */ size, so that we are able to store the parsed stuff there too. */
uid = malloc (sizeof (*uid) + 2 * src_len + 3); uid = _gpgme_malloc (sizeof (*uid) + 2 * src_len + 3);
if (!uid) if (!uid)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
memset (uid, 0, sizeof *uid); memset (uid, 0, sizeof *uid);
@ -258,7 +259,7 @@ _gpgme_key_add_sig (gpgme_key_t key, char *src)
/* We can malloc a buffer of the same length, because the converted /* We can malloc a buffer of the same length, because the converted
string will never be larger. Actually we allocate it twice the string will never be larger. Actually we allocate it twice the
size, so that we are able to store the parsed stuff there too. */ size, so that we are able to store the parsed stuff there too. */
sig = malloc (sizeof (*sig) + 2 * src_len + 3); sig = _gpgme_malloc (sizeof (*sig) + 2 * src_len + 3);
if (!sig) if (!sig)
return NULL; return NULL;
memset (sig, 0, sizeof *sig); memset (sig, 0, sizeof *sig);
@ -330,12 +331,12 @@ gpgme_key_unref (gpgme_key_t key)
{ {
gpgme_subkey_t next = subkey->next; gpgme_subkey_t next = subkey->next;
if (subkey->fpr) if (subkey->fpr)
free (subkey->fpr); _gpgme_free (subkey->fpr);
if (subkey->curve) if (subkey->curve)
free (subkey->curve); _gpgme_free (subkey->curve);
if (subkey->card_number) if (subkey->card_number)
free (subkey->card_number); _gpgme_free (subkey->card_number);
free (subkey); _gpgme_free (subkey);
subkey = next; subkey = next;
} }
@ -358,22 +359,22 @@ gpgme_key_unref (gpgme_key_t key)
notation = next_notation; notation = next_notation;
} }
free (keysig); _gpgme_free (keysig);
keysig = next_keysig; keysig = next_keysig;
} }
free (uid); _gpgme_free (uid);
uid = next_uid; uid = next_uid;
} }
if (key->issuer_serial) if (key->issuer_serial)
free (key->issuer_serial); _gpgme_free (key->issuer_serial);
if (key->issuer_name) if (key->issuer_name)
free (key->issuer_name); _gpgme_free (key->issuer_name);
if (key->chain_id) if (key->chain_id)
free (key->chain_id); _gpgme_free (key->chain_id);
free (key); _gpgme_free (key);
} }

View File

@ -41,6 +41,7 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
struct key_queue_item_s struct key_queue_item_s
@ -385,7 +386,7 @@ parse_sec_field15 (gpgme_key_t key, gpgme_subkey_t subkey, char *field)
/* Fields starts with a hex digit; thus it is a serial number. */ /* Fields starts with a hex digit; thus it is a serial number. */
key->secret = 1; key->secret = 1;
subkey->is_cardkey = 1; subkey->is_cardkey = 1;
subkey->card_number = strdup (field); subkey->card_number = _gpgme_strdup (field);
if (!subkey->card_number) if (!subkey->card_number)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -564,7 +565,7 @@ keylist_colon_handler (void *priv, char *line)
/* Field 8 has the X.509 serial number. */ /* Field 8 has the X.509 serial number. */
if (fields >= 8 && (rectype == RT_CRT || rectype == RT_CRS)) if (fields >= 8 && (rectype == RT_CRT || rectype == RT_CRS))
{ {
key->issuer_serial = strdup (field[7]); key->issuer_serial = _gpgme_strdup (field[7]);
if (!key->issuer_serial) if (!key->issuer_serial)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -598,7 +599,7 @@ keylist_colon_handler (void *priv, char *line)
/* Field 17 has the curve name for ECC. */ /* Field 17 has the curve name for ECC. */
if (fields >= 17 && *field[16]) if (fields >= 17 && *field[16])
{ {
subkey->curve = strdup (field[16]); subkey->curve = _gpgme_strdup (field[16]);
if (!subkey->curve) if (!subkey->curve)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -671,7 +672,7 @@ keylist_colon_handler (void *priv, char *line)
/* Field 17 has the curve name for ECC. */ /* Field 17 has the curve name for ECC. */
if (fields >= 17 && *field[16]) if (fields >= 17 && *field[16])
{ {
subkey->curve = strdup (field[16]); subkey->curve = _gpgme_strdup (field[16]);
if (!subkey->curve) if (!subkey->curve)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -702,7 +703,7 @@ keylist_colon_handler (void *priv, char *line)
subkey = key->_last_subkey; subkey = key->_last_subkey;
if (!subkey->fpr) if (!subkey->fpr)
{ {
subkey->fpr = strdup (field[9]); subkey->fpr = _gpgme_strdup (field[9]);
if (!subkey->fpr) if (!subkey->fpr)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -711,7 +712,7 @@ keylist_colon_handler (void *priv, char *line)
/* Field 13 has the gpgsm chain ID (take only the first one). */ /* Field 13 has the gpgsm chain ID (take only the first one). */
if (fields >= 13 && !key->chain_id && *field[12]) if (fields >= 13 && !key->chain_id && *field[12])
{ {
key->chain_id = strdup (field[12]); key->chain_id = _gpgme_strdup (field[12]);
if (!key->chain_id) if (!key->chain_id)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -858,7 +859,7 @@ _gpgme_op_keylist_event_cb (void *data, gpgme_event_io_t type, void *type_data)
if (err) if (err)
return; return;
q = malloc (sizeof *q); q = _gpgme_malloc (sizeof *q);
if (!q) if (!q)
{ {
gpgme_key_unref (key); gpgme_key_unref (key);
@ -1000,7 +1001,7 @@ gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key)
opd->key_cond = 0; opd->key_cond = 0;
*r_key = queue_item->key; *r_key = queue_item->key;
free (queue_item); _gpgme_free (queue_item);
return TRACE_SUC2 ("key=%p (%s)", *r_key, return TRACE_SUC2 ("key=%p (%s)", *r_key,
((*r_key)->subkeys && (*r_key)->subkeys->fpr) ? ((*r_key)->subkeys && (*r_key)->subkeys->fpr) ?

View File

@ -81,6 +81,7 @@ GPGME_1.1 {
gpgme_op_passwd_start; gpgme_op_passwd_start;
gpgme_op_passwd; gpgme_op_passwd;
gpgme_set_global_malloc_hooks;
gpgme_set_global_flag; gpgme_set_global_flag;
gpgme_io_writen; gpgme_io_writen;

69
src/mem.c Normal file
View File

@ -0,0 +1,69 @@
/* gpgme.c - GnuPG Made Easy.
Copyright (C) 2014 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "gpgme.h"
#include "util.h"
#include "mem.h"
/* The default memory management functions. */
static struct gpgme_malloc_hooks _gpgme_default_malloc_hooks =
{ malloc, calloc, realloc, free };
void *
_gpgme_malloc (size_t size)
{
return _gpgme_default_malloc_hooks.malloc (size);
}
void *
_gpgme_calloc (size_t nmemb, size_t size)
{
return _gpgme_default_malloc_hooks.calloc (nmemb, size);
}
void *
_gpgme_realloc (void *p, size_t size)
{
return _gpgme_default_malloc_hooks.realloc (p, size);
}
void
_gpgme_free (void *p)
{
_gpgme_default_malloc_hooks.free (p);
}
char *
_gpgme_strdup (const char *s)
{
char *r = _gpgme_malloc (strlen(s)+1);
stpcpy (r, s);
return r;
}
void
_gpgme_set_global_malloc_hooks (gpgme_malloc_hooks_t malloc_hooks)
{
_gpgme_default_malloc_hooks = *malloc_hooks;
}

31
src/mem.h Normal file
View File

@ -0,0 +1,31 @@
/* gpgme.c - GnuPG Made Easy.
Copyright (C) 2014 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MEM_H
#define MEM_H
#include "gpgme.h"
void *_gpgme_malloc (size_t);
void *_gpgme_calloc (size_t, size_t);
void *_gpgme_realloc (void *, size_t);
void _gpgme_free (void *);
char *_gpgme_strdup (const char *);
void _gpgme_set_global_malloc_hooks (gpgme_malloc_hooks_t);
#endif

View File

@ -32,6 +32,7 @@
#include "ops.h" #include "ops.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
gpgme_error_t gpgme_error_t
@ -54,7 +55,7 @@ _gpgme_op_data_lookup (gpgme_ctx_t ctx, ctx_op_data_id_t type, void **hook,
return 0; return 0;
} }
data = calloc (1, sizeof (struct ctx_op_data) + size); data = _gpgme_calloc (1, sizeof (struct ctx_op_data) + size);
if (!data) if (!data)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
data->magic = CTX_OP_DATA_MAGIC; data->magic = CTX_OP_DATA_MAGIC;
@ -199,7 +200,7 @@ _gpgme_parse_inv_recp (char *args, gpgme_invalid_key_t *key)
char *tail; char *tail;
long int reason; long int reason;
inv_key = malloc (sizeof (*inv_key)); inv_key = _gpgme_malloc (sizeof (*inv_key));
if (!inv_key) if (!inv_key)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
inv_key->next = NULL; inv_key->next = NULL;
@ -208,7 +209,7 @@ _gpgme_parse_inv_recp (char *args, gpgme_invalid_key_t *key)
if (errno || args == tail || (*tail && *tail != ' ')) if (errno || args == tail || (*tail && *tail != ' '))
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (inv_key); _gpgme_free (inv_key);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
@ -280,10 +281,10 @@ _gpgme_parse_inv_recp (char *args, gpgme_invalid_key_t *key)
tail++; tail++;
if (*tail) if (*tail)
{ {
inv_key->fpr = strdup (tail); inv_key->fpr = _gpgme_strdup (tail);
if (!inv_key->fpr) if (!inv_key->fpr)
{ {
free (inv_key); _gpgme_free (inv_key);
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
} }
@ -329,7 +330,7 @@ _gpgme_parse_plaintext (char *args, char **filenamep)
*tail = '\0'; *tail = '\0';
if (filenamep && *args != '\0') if (filenamep && *args != '\0')
{ {
char *filename = strdup (args); char *filename = _gpgme_strdup (args);
if (!filename) if (!filename)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();

View File

@ -33,6 +33,7 @@
#include "ops.h" #include "ops.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
typedef struct typedef struct
@ -50,9 +51,9 @@ release_op_data (void *hook)
op_data_t opd = (op_data_t) hook; op_data_t opd = (op_data_t) hook;
if (opd->passphrase_info) if (opd->passphrase_info)
free (opd->passphrase_info); _gpgme_free (opd->passphrase_info);
if (opd->uid_hint) if (opd->uid_hint)
free (opd->uid_hint); _gpgme_free (opd->uid_hint);
} }
@ -75,8 +76,8 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code,
{ {
case GPGME_STATUS_USERID_HINT: case GPGME_STATUS_USERID_HINT:
if (opd->uid_hint) if (opd->uid_hint)
free (opd->uid_hint); _gpgme_free (opd->uid_hint);
if (!(opd->uid_hint = strdup (args))) if (!(opd->uid_hint = _gpgme_strdup (args)))
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
break; break;
@ -94,8 +95,8 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code,
case GPGME_STATUS_NEED_PASSPHRASE_SYM: case GPGME_STATUS_NEED_PASSPHRASE_SYM:
case GPGME_STATUS_NEED_PASSPHRASE_PIN: case GPGME_STATUS_NEED_PASSPHRASE_PIN:
if (opd->passphrase_info) if (opd->passphrase_info)
free (opd->passphrase_info); _gpgme_free (opd->passphrase_info);
opd->passphrase_info = strdup (args); opd->passphrase_info = _gpgme_strdup (args);
if (!opd->passphrase_info) if (!opd->passphrase_info)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
break; break;

View File

@ -49,6 +49,7 @@
#include "sema.h" #include "sema.h"
#include "ath.h" #include "ath.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
void void
@ -224,7 +225,7 @@ _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
notify_table_item_t newtbl; notify_table_item_t newtbl;
size_t newsize = notify_table_size + 64; size_t newsize = notify_table_size + 64;
newtbl = calloc (newsize, sizeof *newtbl); newtbl = _gpgme_calloc (newsize, sizeof *newtbl);
if (!newtbl) if (!newtbl)
{ {
res = -1; res = -1;
@ -238,7 +239,7 @@ _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
newtbl[idx].handler = NULL; newtbl[idx].handler = NULL;
newtbl[idx].value = NULL; newtbl[idx].value = NULL;
} }
free (notify_table); _gpgme_free (notify_table);
notify_table = newtbl; notify_table = newtbl;
idx = notify_table_size; idx = notify_table_size;
notify_table_size = newsize; notify_table_size = newsize;

View File

@ -30,6 +30,7 @@
#include "util.h" #include "util.h"
#include "sys-util.h" #include "sys-util.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* These variables store the malloced name of alternative default /* These variables store the malloced name of alternative default
binaries. The are set only once by gpgme_set_global_flag. */ binaries. The are set only once by gpgme_set_global_flag. */
@ -49,7 +50,7 @@ _gpgme_set_default_gpg_name (const char *name)
name = s + 1; name = s + 1;
if (!default_gpg_name) if (!default_gpg_name)
default_gpg_name = strdup (name); default_gpg_name = _gpgme_strdup (name);
return !default_gpg_name; return !default_gpg_name;
} }
@ -66,7 +67,7 @@ _gpgme_set_default_gpgconf_name (const char *name)
name = s + 1; name = s + 1;
if (!default_gpgconf_name) if (!default_gpgconf_name)
default_gpgconf_name = strdup (name); default_gpgconf_name = _gpgme_strdup (name);
return !default_gpgconf_name; return !default_gpgconf_name;
} }
@ -86,7 +87,7 @@ walk_path (const char *pgm)
orig_path = "/bin:/usr/bin"; orig_path = "/bin:/usr/bin";
#endif #endif
fname = malloc (strlen (orig_path) + 1 + strlen (pgm) + 1); fname = _gpgme_malloc (strlen (orig_path) + 1 + strlen (pgm) + 1);
if (!fname) if (!fname)
return NULL; return NULL;
@ -108,7 +109,7 @@ walk_path (const char *pgm)
_gpgme_debug (DEBUG_ENGINE, "gpgme-walk_path: '%s' not found in '%s'", _gpgme_debug (DEBUG_ENGINE, "gpgme-walk_path: '%s' not found in '%s'",
pgm, orig_path); pgm, orig_path);
free (fname); _gpgme_free (fname);
return NULL; return NULL;
} }

View File

@ -29,6 +29,7 @@
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
gpgme_error_t gpgme_error_t
@ -45,7 +46,7 @@ _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
if (code != GPGME_STATUS_PROGRESS || !*args || !ctx->progress_cb) if (code != GPGME_STATUS_PROGRESS || !*args || !ctx->progress_cb)
return 0; return 0;
args_cpy = strdup (args); args_cpy = _gpgme_strdup (args);
if (!args_cpy) if (!args_cpy)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -77,6 +78,6 @@ _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
if (type != 'X') if (type != 'X')
ctx->progress_cb (ctx->progress_cb_value, args_cpy, type, current, total); ctx->progress_cb (ctx->progress_cb_value, args_cpy, type, current, total);
free (args_cpy); _gpgme_free (args_cpy);
return 0; return 0;
} }

View File

@ -142,7 +142,7 @@ __add_to_environ (const char *name, const char *value, const char *combined,
char **new_environ; char **new_environ;
/* We allocated this space; we can extend it. */ /* We allocated this space; we can extend it. */
new_environ = (char **) realloc (last_environ, new_environ = (char **) _gpgme_realloc (last_environ,
(size + 2) * sizeof (char *)); (size + 2) * sizeof (char *));
if (new_environ == NULL) if (new_environ == NULL)
{ {
@ -177,7 +177,7 @@ __add_to_environ (const char *name, const char *value, const char *combined,
if (__builtin_expect (new_environ[size] == NULL, 1)) if (__builtin_expect (new_environ[size] == NULL, 1))
#endif #endif
{ {
new_environ[size] = (char *) malloc (namelen + 1 + vallen); new_environ[size] = (char *) _gpgme_malloc (namelen + 1 + vallen);
if (__builtin_expect (new_environ[size] == NULL, 0)) if (__builtin_expect (new_environ[size] == NULL, 0))
{ {
__set_errno (ENOMEM); __set_errno (ENOMEM);
@ -235,7 +235,7 @@ __add_to_environ (const char *name, const char *value, const char *combined,
if (__builtin_expect (np == NULL, 1)) if (__builtin_expect (np == NULL, 1))
#endif #endif
{ {
np = malloc (namelen + 1 + vallen); np = _gpgme_malloc (namelen + 1 + vallen);
if (__builtin_expect (np == NULL, 0)) if (__builtin_expect (np == NULL, 0))
{ {
UNLOCK; UNLOCK;
@ -321,7 +321,7 @@ clearenv (void)
if (__environ == last_environ && __environ != NULL) if (__environ == last_environ && __environ != NULL)
{ {
/* We allocated this environment so we can free it. */ /* We allocated this environment so we can free it. */
free (__environ); _gpgme_free (__environ);
last_environ = NULL; last_environ = NULL;
} }

View File

@ -31,6 +31,7 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* Free the signature notation object and all associated resources. /* Free the signature notation object and all associated resources.
@ -40,12 +41,12 @@ void
_gpgme_sig_notation_free (gpgme_sig_notation_t notation) _gpgme_sig_notation_free (gpgme_sig_notation_t notation)
{ {
if (notation->name) if (notation->name)
free (notation->name); _gpgme_free (notation->name);
if (notation->value) if (notation->value)
free (notation->value); _gpgme_free (notation->value);
free (notation); _gpgme_free (notation);
} }
@ -77,7 +78,7 @@ _gpgme_sig_notation_create (gpgme_sig_notation_t *notationp,
if (name && !(flags & GPGME_SIG_NOTATION_HUMAN_READABLE)) if (name && !(flags & GPGME_SIG_NOTATION_HUMAN_READABLE))
return gpg_error (GPG_ERR_INV_VALUE); return gpg_error (GPG_ERR_INV_VALUE);
notation = calloc (1, sizeof (*notation)); notation = _gpgme_calloc (1, sizeof (*notation));
if (!notation) if (!notation)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -88,7 +89,7 @@ _gpgme_sig_notation_create (gpgme_sig_notation_t *notationp,
{ {
/* We add a trailing '\0' for stringification in the good /* We add a trailing '\0' for stringification in the good
case. */ case. */
notation->name = malloc (name_len + 1); notation->name = _gpgme_malloc (name_len + 1);
if (!notation->name) if (!notation->name)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -104,7 +105,7 @@ _gpgme_sig_notation_create (gpgme_sig_notation_t *notationp,
{ {
/* We add a trailing '\0' for stringification in the good /* We add a trailing '\0' for stringification in the good
case. */ case. */
notation->value = malloc (value_len + 1); notation->value = _gpgme_malloc (value_len + 1);
if (!notation->value) if (!notation->value)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -234,7 +235,7 @@ _gpgme_parse_notation (gpgme_sig_notation_t *notationp,
/* Small sanity check. */ /* Small sanity check. */
if (4 + 2 + 2 + name_len + value_len > len) if (4 + 2 + 2 + name_len + value_len > len)
{ {
free (decoded_data); _gpgme_free (decoded_data);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
@ -256,6 +257,6 @@ _gpgme_parse_notation (gpgme_sig_notation_t *notationp,
err = _gpgme_sig_notation_create (notationp, name, name_len, err = _gpgme_sig_notation_create (notationp, name, name_len,
value, value_len, flags); value, value_len, flags);
free (decoded_data); _gpgme_free (decoded_data);
return err; return err;
} }

View File

@ -33,6 +33,7 @@
#include "ops.h" #include "ops.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
typedef struct typedef struct
@ -65,16 +66,16 @@ release_op_data (void *hook)
{ {
gpgme_invalid_key_t next = invalid_signer->next; gpgme_invalid_key_t next = invalid_signer->next;
if (invalid_signer->fpr) if (invalid_signer->fpr)
free (invalid_signer->fpr); _gpgme_free (invalid_signer->fpr);
free (invalid_signer); _gpgme_free (invalid_signer);
invalid_signer = next; invalid_signer = next;
} }
while (sig) while (sig)
{ {
gpgme_new_signature_t next = sig->next; gpgme_new_signature_t next = sig->next;
free (sig->fpr); _gpgme_free (sig->fpr);
free (sig); _gpgme_free (sig);
sig = next; sig = next;
} }
} }
@ -148,7 +149,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
gpgme_new_signature_t sig; gpgme_new_signature_t sig;
char *tail; char *tail;
sig = malloc (sizeof (*sig)); sig = _gpgme_malloc (sizeof (*sig));
if (!sig) if (!sig)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -169,14 +170,14 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
default: default:
/* The backend engine is not behaving. */ /* The backend engine is not behaving. */
free (sig); _gpgme_free (sig);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
args++; args++;
if (*args != ' ') if (*args != ' ')
{ {
free (sig); _gpgme_free (sig);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
@ -185,7 +186,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); _gpgme_free (sig);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -194,7 +195,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); _gpgme_free (sig);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -205,7 +206,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); _gpgme_free (sig);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -214,7 +215,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
if (sig->timestamp == -1 || args == tail || *tail != ' ') if (sig->timestamp == -1 || args == tail || *tail != ' ')
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); _gpgme_free (sig);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -224,7 +225,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
if (!*args) if (!*args)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); _gpgme_free (sig);
return trace_gpg_error (GPG_ERR_INV_ENGINE); return trace_gpg_error (GPG_ERR_INV_ENGINE);
} }
@ -232,10 +233,10 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp,
if (tail) if (tail)
*tail = '\0'; *tail = '\0';
sig->fpr = strdup (args); sig->fpr = _gpgme_strdup (args);
if (!sig->fpr) if (!sig->fpr)
{ {
free (sig); _gpgme_free (sig);
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
*sigp = sig; *sigp = sig;

View File

@ -32,6 +32,7 @@
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* Delete all signers from CTX. */ /* Delete all signers from CTX. */
@ -78,7 +79,7 @@ gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key)
int n = ctx->signers_size + 5; int n = ctx->signers_size + 5;
int j; int j;
newarr = realloc (ctx->signers, n * sizeof (*newarr)); newarr = _gpgme_realloc (ctx->signers, n * sizeof (*newarr));
if (!newarr) if (!newarr)
return TRACE_ERR (gpg_error_from_syserror ()); return TRACE_ERR (gpg_error_from_syserror ());
for (j = ctx->signers_size; j < n; j++) for (j = ctx->signers_size; j < n; j++)

View File

@ -31,6 +31,7 @@
#include "ops.h" #include "ops.h"
#include "sema.h" #include "sema.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* Protects all reference counters in trust items. All other accesses /* Protects all reference counters in trust items. All other accesses
@ -45,7 +46,7 @@ _gpgme_trust_item_new (gpgme_trust_item_t *r_item)
{ {
gpgme_trust_item_t item; gpgme_trust_item_t item;
item = calloc (1, sizeof *item); item = _gpgme_calloc (1, sizeof *item);
if (!item) if (!item)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
item->_refs = 1; item->_refs = 1;
@ -88,8 +89,8 @@ gpgme_trust_item_unref (gpgme_trust_item_t item)
UNLOCK (trust_item_ref_lock); UNLOCK (trust_item_ref_lock);
if (item->name) if (item->name)
free (item->name); _gpgme_free (item->name);
free (item); _gpgme_free (item);
} }

View File

@ -32,6 +32,7 @@
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "mem.h"
struct trust_queue_item_s struct trust_queue_item_s
@ -108,7 +109,7 @@ trustlist_colon_handler (void *priv, char *line)
item->_validity[0] = *p; item->_validity[0] = *p;
break; break;
case 9: /* user ID */ case 9: /* user ID */
item->name = strdup (p); item->name = _gpgme_strdup (p);
if (!item->name) if (!item->name)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
@ -143,7 +144,7 @@ _gpgme_op_trustlist_event_cb (void *data, gpgme_event_io_t type,
if (err) if (err)
return; return;
q = malloc (sizeof *q); q = _gpgme_malloc (sizeof *q);
if (!q) if (!q)
{ {
gpgme_trust_item_unref (item); gpgme_trust_item_unref (item);
@ -239,7 +240,7 @@ gpgme_op_trustlist_next (gpgme_ctx_t ctx, gpgme_trust_item_t *r_item)
opd->trust_queue = q->next; opd->trust_queue = q->next;
*r_item = q->item; *r_item = q->item;
free (q); _gpgme_free (q);
if ((*r_item)->type == 1) if ((*r_item)->type == 1)
{ {
TRACE_SUC5 ("trust_item=%p: %s: owner trust %s with level %i " TRACE_SUC5 ("trust_item=%p: %s: owner trust %s with level %i "

View File

@ -81,11 +81,9 @@ _gpgme_stpcpy (char *a, const char *b)
#define stpcpy(a,b) _gpgme_stpcpy ((a), (b)) #define stpcpy(a,b) _gpgme_stpcpy ((a), (b))
#endif /*!HAVE_STPCPY*/ #endif /*!HAVE_STPCPY*/
#if !HAVE_VASPRINTF
#include <stdarg.h> #include <stdarg.h>
int vasprintf (char **result, const char *format, va_list args); int _gpgme_vasprintf (char **result, const char *format, va_list args);
int asprintf (char **result, const char *format, ...); int _gpgme_asprintf (char **result, const char *format, ...);
#endif
#if REPLACE_TTYNAME_R #if REPLACE_TTYNAME_R
int _gpgme_ttyname_r (int fd, char *buf, size_t buflen); int _gpgme_ttyname_r (int fd, char *buf, size_t buflen);

View File

@ -40,7 +40,14 @@ Boston, MA 02111-1307, USA. */
#ifdef TEST #ifdef TEST
#define _gpgme_malloc malloc
#define _gpgme_calloc calloc
#define _gpgme_realloc realloc
#define _gpgme_strdup strdup
#define _gpgme_free free
int global_total_width; int global_total_width;
#else
#include "mem.h"
#endif #endif
static int int_vasprintf (char **, const char *, va_list *); static int int_vasprintf (char **, const char *, va_list *);
@ -54,7 +61,7 @@ int_vasprintf (result, format, args)
#ifdef HAVE_W32CE_SYSTEM #ifdef HAVE_W32CE_SYSTEM
/* No va_copy and the replacement above doesn't work. */ /* No va_copy and the replacement above doesn't work. */
#define MAX_STRLEN 256 #define MAX_STRLEN 256
*result = malloc (MAX_STRLEN); *result = _gpgme_malloc (MAX_STRLEN);
if (*result != NULL) if (*result != NULL)
{ {
int res = _vsnprintf (*result, MAX_STRLEN, format, *args); int res = _vsnprintf (*result, MAX_STRLEN, format, *args);
@ -141,7 +148,7 @@ int_vasprintf (result, format, args)
#ifdef TEST #ifdef TEST
global_total_width = total_width; global_total_width = total_width;
#endif #endif
*result = malloc (total_width); *result = _gpgme_malloc (total_width);
if (*result != NULL) if (*result != NULL)
return vsprintf (*result, format, *args); return vsprintf (*result, format, *args);
else else
@ -150,7 +157,7 @@ int_vasprintf (result, format, args)
} }
int int
vasprintf (result, format, args) _gpgme_vasprintf (result, format, args)
char **result; char **result;
const char *format; const char *format;
#if defined (_BSD_VA_LIST_) && defined (__FreeBSD__) #if defined (_BSD_VA_LIST_) && defined (__FreeBSD__)
@ -159,18 +166,28 @@ vasprintf (result, format, args)
va_list args; va_list args;
#endif #endif
{ {
return int_vasprintf (result, format, &args); #if defined (_BSD_VA_LIST_) && defined (__FreeBSD__)
_BSD_VA_LIST_ cp;
#else
va_list cp;
#endif
int ret;
va_copy(cp, args);
ret = int_vasprintf (result, format, &cp);
va_end(cp);
return ret;
} }
int int
asprintf (char **buf, const char *fmt, ...) _gpgme_asprintf (char **buf, const char *fmt, ...)
{ {
int status; int status;
va_list ap; va_list ap;
va_start (ap, fmt); va_start (ap, fmt);
status = vasprintf (buf, fmt, ap); status = _gpgme_vasprintf (buf, fmt, ap);
va_end (ap); va_end (ap);
return status; return status;
} }
@ -184,7 +201,7 @@ checkit (const char* format, ...)
char *result; char *result;
va_start (args, format); va_start (args, format);
vasprintf (&result, format, args); _gpgme_vasprintf (&result, format, args);
if (strlen (result) < global_total_width) if (strlen (result) < global_total_width)
printf ("PASS: "); printf ("PASS: ");
else else

View File

@ -32,6 +32,7 @@
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "mem.h"
typedef struct typedef struct
@ -65,15 +66,15 @@ release_op_data (void *hook)
} }
if (sig->fpr) if (sig->fpr)
free (sig->fpr); _gpgme_free (sig->fpr);
if (sig->pka_address) if (sig->pka_address)
free (sig->pka_address); _gpgme_free (sig->pka_address);
free (sig); _gpgme_free (sig);
sig = next; sig = next;
} }
if (opd->result.file_name) if (opd->result.file_name)
free (opd->result.file_name); _gpgme_free (opd->result.file_name);
} }
@ -249,7 +250,7 @@ prepare_new_sig (op_data_t opd)
} }
else else
{ {
sig = calloc (1, sizeof (*sig)); sig = _gpgme_calloc (1, sizeof (*sig));
if (!sig) if (!sig)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
if (!opd->result.signatures) if (!opd->result.signatures)
@ -385,7 +386,7 @@ parse_new_sig (op_data_t opd, gpgme_status_code_t code, char *args,
if (*args) if (*args)
{ {
sig->fpr = strdup (args); sig->fpr = _gpgme_strdup (args);
if (!sig->fpr) if (!sig->fpr)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
@ -408,8 +409,8 @@ parse_valid_sig (gpgme_signature_t sig, char *args, gpgme_protocol_t protocol)
return gpg_error (GPG_ERR_GENERAL); return gpg_error (GPG_ERR_GENERAL);
if (sig->fpr) if (sig->fpr)
free (sig->fpr); _gpgme_free (sig->fpr);
sig->fpr = strdup (args); sig->fpr = _gpgme_strdup (args);
if (!sig->fpr) if (!sig->fpr)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -550,14 +551,14 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args)
if (!notation->value) if (!notation->value)
{ {
dest = notation->value = malloc (len); dest = notation->value = _gpgme_malloc (len);
if (!dest) if (!dest)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
else else
{ {
int cur_len = strlen (notation->value); int cur_len = strlen (notation->value);
dest = realloc (notation->value, len + strlen (notation->value)); dest = _gpgme_realloc (notation->value, len + strlen (notation->value));
if (!dest) if (!dest)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
notation->value = dest; notation->value = dest;
@ -753,7 +754,7 @@ _gpgme_verify_status_handler (void *priv, gpgme_status_code_t code, char *args)
end = strchr (args, ' '); end = strchr (args, ' ');
if (end) if (end)
*end = 0; *end = 0;
sig->pka_address = strdup (args); sig->pka_address = _gpgme_strdup (args);
break; break;
case GPGME_STATUS_ERROR: case GPGME_STATUS_ERROR:
@ -784,7 +785,7 @@ _gpgme_verify_status_handler (void *priv, gpgme_status_code_t code, char *args)
} }
/* Note that there is no need to release the members of SIG /* Note that there is no need to release the members of SIG
because we won't be here if they have been set. */ because we won't be here if they have been set. */
free (sig); _gpgme_free (sig);
opd->current_sig = NULL; opd->current_sig = NULL;
} }
opd->only_newsig_seen = 0; opd->only_newsig_seen = 0;

View File

@ -34,6 +34,7 @@
#include "priv-io.h" #include "priv-io.h"
#include "debug.h" #include "debug.h"
#include "context.h" #include "context.h"
#include "mem.h"
/* For _gpgme_sema_subsystem_init and _gpgme_status_init. */ /* For _gpgme_sema_subsystem_init and _gpgme_status_init. */
#include "sema.h" #include "sema.h"
@ -359,7 +360,7 @@ _gpgme_get_program_version (const char *const file_name)
s = extract_version_string (line, &len); s = extract_version_string (line, &len);
if (!len) if (!len)
return NULL; return NULL;
mark = malloc (len + 1); mark = _gpgme_malloc (len + 1);
if (!mark) if (!mark)
return NULL; return NULL;
memcpy (mark, s, len); memcpy (mark, s, len);

View File

@ -30,6 +30,7 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "util.h" #include "util.h"
#include "mem.h"
static gpgme_error_t static gpgme_error_t
vfs_start (gpgme_ctx_t ctx, int synchronous, vfs_start (gpgme_ctx_t ctx, int synchronous,
@ -132,39 +133,39 @@ _gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
{ {
if (!recp[i]->subkeys || !recp[i]->subkeys->fpr) if (!recp[i]->subkeys || !recp[i]->subkeys->fpr)
{ {
free (container_file_esc); _gpgme_free (container_file_esc);
return gpg_error (GPG_ERR_UNUSABLE_PUBKEY); return gpg_error (GPG_ERR_UNUSABLE_PUBKEY);
} }
if (asprintf (&cmd, "RECIPIENT %s", recp[i]->subkeys->fpr) < 0) if (_gpgme_asprintf (&cmd, "RECIPIENT %s", recp[i]->subkeys->fpr) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (container_file_esc); _gpgme_free (container_file_esc);
return err; return err;
} }
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL, err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
NULL, NULL, op_err); NULL, NULL, op_err);
free (cmd); _gpgme_free (cmd);
if (err || *op_err) if (err || *op_err)
{ {
free (container_file_esc); _gpgme_free (container_file_esc);
return err; return err;
} }
recp++; recp++;
} }
if (asprintf (&cmd, "CREATE -- %s", container_file_esc) < 0) if (_gpgme_asprintf (&cmd, "CREATE -- %s", container_file_esc) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (container_file_esc); _gpgme_free (container_file_esc);
return err; return err;
} }
free (container_file_esc); _gpgme_free (container_file_esc);
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL, err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
NULL, NULL, op_err); NULL, NULL, op_err);
free (cmd); _gpgme_free (cmd);
return err; return err;
} }

View File

@ -29,6 +29,7 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#include "util.h" #include "util.h"
#include "mem.h"
typedef struct typedef struct
{ {
@ -71,8 +72,8 @@ _gpgme_vfs_mount_status_handler (void *priv, const char *code, const char *args)
if (! strcasecmp ("MOUNTPOINT", code)) if (! strcasecmp ("MOUNTPOINT", code))
{ {
if (opd->result.mount_dir) if (opd->result.mount_dir)
free (opd->result.mount_dir); _gpgme_free (opd->result.mount_dir);
opd->result.mount_dir = strdup (args); opd->result.mount_dir = _gpgme_strdup (args);
} }
return 0; return 0;
@ -182,17 +183,17 @@ _gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
if (err) if (err)
return err; return err;
if (asprintf (&cmd, "OPEN -- %s", container_file_esc) < 0) if (_gpgme_asprintf (&cmd, "OPEN -- %s", container_file_esc) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (container_file_esc); _gpgme_free (container_file_esc);
return err; return err;
} }
free (container_file_esc); _gpgme_free (container_file_esc);
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL, err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
NULL, NULL, op_err); NULL, NULL, op_err);
free (cmd); _gpgme_free (cmd);
if (err || *op_err) if (err || *op_err)
return err; return err;
@ -204,23 +205,23 @@ _gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
if (err) if (err)
return err; return err;
if (asprintf (&cmd, "MOUNT -- %s", mount_dir_esc) < 0) if (_gpgme_asprintf (&cmd, "MOUNT -- %s", mount_dir_esc) < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
free (mount_dir_esc); _gpgme_free (mount_dir_esc);
return err; return err;
} }
free (mount_dir_esc); _gpgme_free (mount_dir_esc);
} }
else else
{ {
if (asprintf (&cmd, "MOUNT") < 0) if (_gpgme_asprintf (&cmd, "MOUNT") < 0)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL, err = gpgme_op_vfs_transact (ctx, cmd, NULL, NULL, NULL, NULL,
_gpgme_vfs_mount_status_handler, ctx, op_err); _gpgme_vfs_mount_status_handler, ctx, op_err);
free (cmd); _gpgme_free (cmd);
return err; return err;
} }

View File

@ -58,14 +58,14 @@ wchar_to_utf8 (const wchar_t *string)
return NULL; return NULL;
} }
result = malloc (n+1); result = _gpgme_malloc (n+1);
if (!result) if (!result)
return NULL; return NULL;
n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL); n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
if (n < 0) if (n < 0)
{ {
free (result); _gpgme_free (result);
gpg_err_set_errno (EINVAL); gpg_err_set_errno (EINVAL);
result = NULL; result = NULL;
} }
@ -97,14 +97,14 @@ utf8_to_wchar (const char *string)
gpg_err_set_errno (ENOMEM); gpg_err_set_errno (ENOMEM);
return NULL; return NULL;
} }
result = malloc (nbytes); result = _gpgme_malloc (nbytes);
if (!result) if (!result)
return NULL; return NULL;
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n); n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
if (n < 0) if (n < 0)
{ {
free (result); _gpgme_free (result);
gpg_err_set_errno (EINVAL); gpg_err_set_errno (EINVAL);
result = NULL; result = NULL;
} }
@ -124,7 +124,7 @@ getenv (const char *name)
if (past_result) if (past_result)
{ {
free (past_result); _gpgme_free (past_result);
past_result = NULL; past_result = NULL;
} }
@ -179,7 +179,7 @@ DeleteFileA (LPCSTR lpFileName)
result = DeleteFileW (filename); result = DeleteFileW (filename);
err = GetLastError (); err = GetLastError ();
free (filename); _gpgme_free (filename);
SetLastError (err); SetLastError (err);
return result; return result;
} }
@ -204,7 +204,7 @@ CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwSharedMode,
dwFlagsAndAttributes, hTemplateFile); dwFlagsAndAttributes, hTemplateFile);
err = GetLastError (); err = GetLastError ();
free (filename); _gpgme_free (filename);
SetLastError (err); SetLastError (err);
return result; return result;
} }
@ -242,7 +242,7 @@ CreateProcessA (LPCSTR pszImageName, LPSTR pszCmdLine,
if (!cmd_line) if (!cmd_line)
{ {
if (image_name) if (image_name)
free (image_name); _gpgme_free (image_name);
return 0; return 0;
} }
} }
@ -251,8 +251,8 @@ CreateProcessA (LPCSTR pszImageName, LPSTR pszCmdLine,
fdwCreate, NULL, NULL, NULL, pProcInfo); fdwCreate, NULL, NULL, NULL, pProcInfo);
err = GetLastError (); err = GetLastError ();
free (image_name); _gpgme_free (image_name);
free (cmd_line); _gpgme_free (cmd_line);
SetLastError (err); SetLastError (err);
return result; return result;
} }
@ -278,7 +278,7 @@ RegOpenKeyExA (HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions,
result = RegOpenKeyEx (hKey, subkey, ulOptions, samDesired, phkResult); result = RegOpenKeyEx (hKey, subkey, ulOptions, samDesired, phkResult);
err = GetLastError (); err = GetLastError ();
free (subkey); _gpgme_free (subkey);
SetLastError (err); SetLastError (err);
return result; return result;
} }
@ -307,21 +307,21 @@ RegQueryValueExA (HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved,
err = RegQueryValueExW (hKey, name, lpReserved, lpType, NULL, &data_len); err = RegQueryValueExW (hKey, name, lpReserved, lpType, NULL, &data_len);
if (err || !lpcbData) if (err || !lpcbData)
{ {
free (name); _gpgme_free (name);
return err; return err;
} }
data = malloc (data_len + sizeof (wchar_t)); data = _gpgme_malloc (data_len + sizeof (wchar_t));
if (!data) if (!data)
{ {
free (name); _gpgme_free (name);
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
} }
err = RegQueryValueExW (hKey, name, lpReserved, &type, data, &data_len); err = RegQueryValueExW (hKey, name, lpReserved, &type, data, &data_len);
if (lpType) if (lpType)
*lpType = type; *lpType = type;
free (name); _gpgme_free (name);
/* If err is ERROR_MORE_DATA, there probably was a race condition. /* If err is ERROR_MORE_DATA, there probably was a race condition.
We can punt this to the caller just as well. */ We can punt this to the caller just as well. */
if (err) if (err)
@ -346,7 +346,7 @@ RegQueryValueExA (HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved,
assert (data_c_len <= data_len + sizeof (wchar_t)); assert (data_c_len <= data_len + sizeof (wchar_t));
memcpy (data, data_c, data_c_len); memcpy (data, data_c, data_c_len);
data_len = data_c_len; data_len = data_c_len;
free (data_c); _gpgme_free (data_c);
} }
/* DATA and DATA_LEN now contain the result. */ /* DATA and DATA_LEN now contain the result. */
@ -384,7 +384,7 @@ GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer)
char *buffer_c; char *buffer_c;
DWORD len_c; DWORD len_c;
buffer_w = malloc (sizeof (wchar_t) * len); buffer_w = _gpgme_malloc (sizeof (wchar_t) * len);
if (! buffer_w) if (! buffer_w)
return 0; return 0;
@ -392,7 +392,7 @@ GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer)
/* Give up if we still can't get at it. */ /* Give up if we still can't get at it. */
if (len_w == 0 || len_w >= len) if (len_w == 0 || len_w >= len)
{ {
free (buffer_w); _gpgme_free (buffer_w);
return 0; return 0;
} }
@ -400,7 +400,7 @@ GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer)
buffer_w[len_w] = '\0'; buffer_w[len_w] = '\0';
buffer_c = wchar_to_utf8 (buffer_w); buffer_c = wchar_to_utf8 (buffer_w);
free (buffer_w); _gpgme_free (buffer_w);
if (! buffer_c) if (! buffer_c)
return 0; return 0;
@ -411,7 +411,7 @@ GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer)
return len_c; return len_c;
strcpy (lpBuffer, buffer_c); strcpy (lpBuffer, buffer_c);
free (buffer_c); _gpgme_free (buffer_c);
return len_c - 1; return len_c - 1;
} }
} }
@ -441,7 +441,7 @@ SHGetSpecialFolderPathA (HWND hwndOwner, LPSTR lpszPath, int nFolder,
return 0; return 0;
strncpy (lpszPath, path_c, MAX_PATH); strncpy (lpszPath, path_c, MAX_PATH);
free (path_c); _gpgme_free (path_c);
lpszPath[MAX_PATH - 1] = '\0'; lpszPath[MAX_PATH - 1] = '\0';
return result; return result;
} }
@ -465,7 +465,7 @@ _gpgme_wince_access (const char *fname, int mode)
return -1; return -1;
attr = GetFileAttributes (wfname); attr = GetFileAttributes (wfname);
free (wfname); _gpgme_free (wfname);
if (attr == (DWORD)(-1)) if (attr == (DWORD)(-1))
{ {
gpg_err_set_errno (ENOENT); gpg_err_set_errno (ENOENT);

View File

@ -23,10 +23,11 @@
#include <time.h> #include <time.h>
#include <stdarg.h> #include <stdarg.h>
#include "mem.h"
#ifdef _MSC_VER #ifdef _MSC_VER
typedef int pid_t; typedef int pid_t;
#define strdup _strdup #define strdup _gpgme_strdup
#define strcasecmp _stricmp #define strcasecmp _stricmp
#endif #endif

View File

@ -565,7 +565,7 @@ build_commandline (char **argv)
/* And a trailing zero. */ /* And a trailing zero. */
n++; n++;
buf = p = malloc (n); buf = p = _gpgme_malloc (n);
if (!buf) if (!buf)
return NULL; return NULL;
for (i = 0; argv[i]; i++) for (i = 0; argv[i]; i++)
@ -634,7 +634,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
} }
TRACE_LOG1 ("tmp_name = %s", tmp_name); TRACE_LOG1 ("tmp_name = %s", tmp_name);
args = calloc (2 + i + 1, sizeof (*args)); args = _gpgme_calloc (2 + i + 1, sizeof (*args));
args[0] = (char *) _gpgme_get_w32spawn_path (); args[0] = (char *) _gpgme_get_w32spawn_path ();
args[1] = tmp_name; args[1] = tmp_name;
args[2] = path; args[2] = path;
@ -645,7 +645,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
sec_attr.bInheritHandle = FALSE; sec_attr.bInheritHandle = FALSE;
arg_string = build_commandline (args); arg_string = build_commandline (args);
free (args); _gpgme_free (args);
if (!arg_string) if (!arg_string)
{ {
close (tmp_fd); close (tmp_fd);
@ -676,7 +676,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
&pi)) /* returns process information */ &pi)) /* returns process information */
{ {
TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ());
free (arg_string); _gpgme_free (arg_string);
close (tmp_fd); close (tmp_fd);
DeleteFile (tmp_name); DeleteFile (tmp_name);
@ -685,7 +685,7 @@ _gpgme_io_spawn (const char *path, char * const argv[], unsigned int flags,
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
free (arg_string); _gpgme_free (arg_string);
if (flags & IOSPAWN_FLAG_ALLOW_SET_FG) if (flags & IOSPAWN_FLAG_ALLOW_SET_FG)
_gpgme_allow_set_foreground_window ((pid_t)pi.dwProcessId); _gpgme_allow_set_foreground_window ((pid_t)pi.dwProcessId);
@ -826,13 +826,13 @@ _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
if (nonblock) if (nonblock)
timeout = 0; timeout = 0;
pollfds = calloc (nfds, sizeof *pollfds); pollfds = _gpgme_calloc (nfds, sizeof *pollfds);
if (!pollfds) if (!pollfds)
return -1; return -1;
pollfds_map = calloc (nfds, sizeof *pollfds_map); pollfds_map = _gpgme_calloc (nfds, sizeof *pollfds_map);
if (!pollfds_map) if (!pollfds_map)
{ {
free (pollfds); _gpgme_free (pollfds);
return -1; return -1;
} }
npollfds = 0; npollfds = 0;
@ -928,8 +928,8 @@ _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
} }
leave: leave:
free (pollfds); _gpgme_free (pollfds);
free (pollfds_map); _gpgme_free (pollfds_map);
return TRACE_SYSRES (count); return TRACE_SYSRES (count);
} }

View File

@ -396,7 +396,7 @@ reader (void *arg)
CloseHandle (ctx->have_space_ev); CloseHandle (ctx->have_space_ev);
CloseHandle (ctx->thread_hd); CloseHandle (ctx->thread_hd);
DESTROY_LOCK (ctx->mutex); DESTROY_LOCK (ctx->mutex);
free (ctx); _gpgme_free (ctx);
return TRACE_SUC (); return TRACE_SUC ();
} }
@ -415,7 +415,7 @@ create_reader (int fd)
sec_attr.nLength = sizeof sec_attr; sec_attr.nLength = sizeof sec_attr;
sec_attr.bInheritHandle = FALSE; sec_attr.bInheritHandle = FALSE;
ctx = calloc (1, sizeof *ctx); ctx = _gpgme_calloc (1, sizeof *ctx);
if (!ctx) if (!ctx)
{ {
TRACE_SYSERR (errno); TRACE_SYSERR (errno);
@ -425,7 +425,7 @@ create_reader (int fd)
if (fd < 0 || fd >= MAX_SLAFD || !fd_table[fd].used) if (fd < 0 || fd >= MAX_SLAFD || !fd_table[fd].used)
{ {
TRACE_SYSERR (EIO); TRACE_SYSERR (EIO);
free (ctx); _gpgme_free (ctx);
return NULL; return NULL;
} }
TRACE_LOG4 ("fd=%d -> handle=%p socket=%d dupfrom=%d", TRACE_LOG4 ("fd=%d -> handle=%p socket=%d dupfrom=%d",
@ -449,7 +449,7 @@ create_reader (int fd)
CloseHandle (ctx->have_space_ev); CloseHandle (ctx->have_space_ev);
if (ctx->close_ev) if (ctx->close_ev)
CloseHandle (ctx->close_ev); CloseHandle (ctx->close_ev);
free (ctx); _gpgme_free (ctx);
/* FIXME: Translate the error code. */ /* FIXME: Translate the error code. */
TRACE_SYSERR (EIO); TRACE_SYSERR (EIO);
return NULL; return NULL;
@ -475,7 +475,7 @@ create_reader (int fd)
CloseHandle (ctx->have_space_ev); CloseHandle (ctx->have_space_ev);
if (ctx->close_ev) if (ctx->close_ev)
CloseHandle (ctx->close_ev); CloseHandle (ctx->close_ev);
free (ctx); _gpgme_free (ctx);
TRACE_SYSERR (EIO); TRACE_SYSERR (EIO);
return NULL; return NULL;
} }
@ -766,7 +766,7 @@ writer (void *arg)
CloseHandle (ctx->is_empty); CloseHandle (ctx->is_empty);
CloseHandle (ctx->thread_hd); CloseHandle (ctx->thread_hd);
DESTROY_LOCK (ctx->mutex); DESTROY_LOCK (ctx->mutex);
free (ctx); _gpgme_free (ctx);
return TRACE_SUC (); return TRACE_SUC ();
} }
@ -785,7 +785,7 @@ create_writer (int fd)
sec_attr.nLength = sizeof sec_attr; sec_attr.nLength = sizeof sec_attr;
sec_attr.bInheritHandle = FALSE; sec_attr.bInheritHandle = FALSE;
ctx = calloc (1, sizeof *ctx); ctx = _gpgme_calloc (1, sizeof *ctx);
if (!ctx) if (!ctx)
{ {
TRACE_SYSERR (errno); TRACE_SYSERR (errno);
@ -795,7 +795,7 @@ create_writer (int fd)
if (fd < 0 || fd >= MAX_SLAFD || !fd_table[fd].used) if (fd < 0 || fd >= MAX_SLAFD || !fd_table[fd].used)
{ {
TRACE_SYSERR (EIO); TRACE_SYSERR (EIO);
free (ctx); _gpgme_free (ctx);
return NULL; return NULL;
} }
TRACE_LOG4 ("fd=%d -> handle=%p socket=%d dupfrom=%d", TRACE_LOG4 ("fd=%d -> handle=%p socket=%d dupfrom=%d",
@ -819,7 +819,7 @@ create_writer (int fd)
CloseHandle (ctx->is_empty); CloseHandle (ctx->is_empty);
if (ctx->close_ev) if (ctx->close_ev)
CloseHandle (ctx->close_ev); CloseHandle (ctx->close_ev);
free (ctx); _gpgme_free (ctx);
/* FIXME: Translate the error code. */ /* FIXME: Translate the error code. */
TRACE_SYSERR (EIO); TRACE_SYSERR (EIO);
return NULL; return NULL;
@ -845,7 +845,7 @@ create_writer (int fd)
CloseHandle (ctx->is_empty); CloseHandle (ctx->is_empty);
if (ctx->close_ev) if (ctx->close_ev)
CloseHandle (ctx->close_ev); CloseHandle (ctx->close_ev);
free (ctx); _gpgme_free (ctx);
TRACE_SYSERR (EIO); TRACE_SYSERR (EIO);
return NULL; return NULL;
} }
@ -1323,7 +1323,7 @@ build_commandline (char **argv, int fd0, int fd0_isnull,
n++; /* Need to double inner quotes. */ n++; /* Need to double inner quotes. */
} }
n++; n++;
buf = p = malloc (n); buf = p = _gpgme_malloc (n);
if (! buf) if (! buf)
return NULL; return NULL;
@ -1388,7 +1388,7 @@ build_commandline (char **argv)
/* And a trailing zero. */ /* And a trailing zero. */
n++; n++;
buf = p = malloc (n); buf = p = _gpgme_malloc (n);
if (!buf) if (!buf)
return NULL; return NULL;
for (i = 0; argv[i]; i++) for (i = 0; argv[i]; i++)
@ -1502,7 +1502,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
)) ))
{ {
TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ());
free (cmdline); _gpgme_free (cmdline);
gpg_err_set_errno (EIO); gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -1572,7 +1572,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
} }
TRACE_LOG1 ("tmp_name = %s", tmp_name); TRACE_LOG1 ("tmp_name = %s", tmp_name);
args = calloc (2 + i + 1, sizeof (*args)); args = _gpgme_calloc (2 + i + 1, sizeof (*args));
args[0] = (char *) _gpgme_get_w32spawn_path (); args[0] = (char *) _gpgme_get_w32spawn_path ();
args[1] = tmp_name; args[1] = tmp_name;
args[2] = (char *)path; args[2] = (char *)path;
@ -1583,7 +1583,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
sec_attr.bInheritHandle = FALSE; sec_attr.bInheritHandle = FALSE;
arg_string = build_commandline (args); arg_string = build_commandline (args);
free (args); _gpgme_free (args);
if (!arg_string) if (!arg_string)
{ {
close (tmp_fd); close (tmp_fd);
@ -1615,7 +1615,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
&pi)) /* returns process information */ &pi)) /* returns process information */
{ {
TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ());
free (arg_string); _gpgme_free (arg_string);
close (tmp_fd); close (tmp_fd);
DeleteFileA (tmp_name); DeleteFileA (tmp_name);
@ -1624,7 +1624,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
free (arg_string); _gpgme_free (arg_string);
if (flags & IOSPAWN_FLAG_ALLOW_SET_FG) if (flags & IOSPAWN_FLAG_ALLOW_SET_FG)
_gpgme_allow_set_foreground_window ((pid_t)pi.dwProcessId); _gpgme_allow_set_foreground_window ((pid_t)pi.dwProcessId);

View File

@ -72,7 +72,7 @@ critsect_init (struct critsect_s *s)
return; return;
} }
/* now init it */ /* now init it */
mp = malloc ( sizeof *mp ); mp = _gpgme_malloc ( sizeof *mp );
if (!mp) { if (!mp) {
LeaveCriticalSection (&init_lock); LeaveCriticalSection (&init_lock);
sema_fatal ("out of core while creating critical section lock"); sema_fatal ("out of core while creating critical section lock");
@ -111,7 +111,7 @@ _gpgme_sema_cs_destroy ( struct critsect_s *s )
{ {
if (s && s->priv) { if (s && s->priv) {
DeleteCriticalSection ((CRITICAL_SECTION*)s->priv); DeleteCriticalSection ((CRITICAL_SECTION*)s->priv);
free (s->priv); _gpgme_free (s->priv);
s->priv = NULL; s->priv = NULL;
} }
} }

View File

@ -141,14 +141,14 @@ wchar_to_utf8 (const wchar_t *string)
return NULL; return NULL;
} }
result = malloc (n+1); result = _gpgme_malloc (n+1);
if (!result) if (!result)
return NULL; return NULL;
n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL); n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
if (n < 0) if (n < 0)
{ {
free (result); _gpgme_free (result);
gpg_err_set_errno (EINVAL); gpg_err_set_errno (EINVAL);
result = NULL; result = NULL;
} }
@ -276,12 +276,12 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
goto leave; goto leave;
} }
n1 = nbytes + 1; n1 = nbytes + 1;
result = malloc (n1); result = _gpgme_malloc (n1);
if (!result) if (!result)
goto leave; goto leave;
if (RegQueryValueExA (key_handle, name, 0, &type, (LPBYTE) result, &n1)) if (RegQueryValueExA (key_handle, name, 0, &type, (LPBYTE) result, &n1))
{ {
free (result); _gpgme_free (result);
result = NULL; result = NULL;
goto leave; goto leave;
} }
@ -294,42 +294,42 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
char *tmp; char *tmp;
n1 += 1000; n1 += 1000;
tmp = malloc (n1 + 1); tmp = _gpgme_malloc (n1 + 1);
if (!tmp) if (!tmp)
goto leave; goto leave;
nbytes = ExpandEnvironmentStrings (result, tmp, n1); nbytes = ExpandEnvironmentStrings (result, tmp, n1);
if (nbytes && nbytes > n1) if (nbytes && nbytes > n1)
{ {
free (tmp); _gpgme_free (tmp);
n1 = nbytes; n1 = nbytes;
tmp = malloc (n1 + 1); tmp = _gpgme_malloc (n1 + 1);
if (!tmp) if (!tmp)
goto leave; goto leave;
nbytes = ExpandEnvironmentStrings (result, tmp, n1); nbytes = ExpandEnvironmentStrings (result, tmp, n1);
if (nbytes && nbytes > 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; goto leave;
} }
tmp[nbytes] = 0; tmp[nbytes] = 0;
free (result); _gpgme_free (result);
result = tmp; result = tmp;
} }
else if (nbytes) /* Okay, reduce the length. */ else if (nbytes) /* Okay, reduce the length. */
{ {
tmp[nbytes] = 0; tmp[nbytes] = 0;
free (result); _gpgme_free (result);
result = malloc (strlen (tmp)+1); result = _gpgme_malloc (strlen (tmp)+1);
if (!result) if (!result)
result = tmp; result = tmp;
else else
{ {
strcpy (result, tmp); strcpy (result, tmp);
free (tmp); _gpgme_free (tmp);
} }
} }
else /* Error - don't expand. */ else /* Error - don't expand. */
{ {
free (tmp); _gpgme_free (tmp);
} }
} }
#endif #endif
@ -352,7 +352,7 @@ _gpgme_get_inst_dir (void)
{ {
wchar_t *moddir; wchar_t *moddir;
moddir = malloc ((MAX_PATH+5) * sizeof *moddir); moddir = _gpgme_malloc ((MAX_PATH+5) * sizeof *moddir);
if (moddir) if (moddir)
{ {
if (!GetModuleFileNameW (my_hmodule, moddir, MAX_PATH)) if (!GetModuleFileNameW (my_hmodule, moddir, MAX_PATH))
@ -369,7 +369,7 @@ _gpgme_get_inst_dir (void)
*p = 0; *p = 0;
} }
} }
free (moddir); _gpgme_free (moddir);
} }
} }
UNLOCK (get_path_lock); UNLOCK (get_path_lock);
@ -382,14 +382,14 @@ find_program_in_dir (const char *dir, const char *name)
{ {
char *result; char *result;
result = malloc (strlen (dir) + 1 + strlen (name) + 1); result = _gpgme_malloc (strlen (dir) + 1 + strlen (name) + 1);
if (!result) if (!result)
return NULL; return NULL;
strcpy (stpcpy (stpcpy (result, dir), "\\"), name); strcpy (stpcpy (stpcpy (result, dir), "\\"), name);
if (access (result, F_OK)) if (access (result, F_OK))
{ {
free (result); _gpgme_free (result);
return NULL; return NULL;
} }
@ -424,7 +424,7 @@ find_program_in_inst_dir (const char *inst_dir, const char *name)
if (dir) if (dir)
{ {
result = find_program_in_dir (dir, name); result = find_program_in_dir (dir, name);
free (dir); _gpgme_free (dir);
return result; return result;
} }
return NULL; return NULL;
@ -440,13 +440,13 @@ find_program_at_standard_place (const char *name)
/* See http://wiki.tcl.tk/17492 for details on compatibility. */ /* See http://wiki.tcl.tk/17492 for details on compatibility. */
if (SHGetSpecialFolderPathA (NULL, path, CSIDL_PROGRAM_FILES, 0)) 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) if (result)
{ {
strcpy (stpcpy (stpcpy (result, path), "\\"), name); strcpy (stpcpy (stpcpy (result, path), "\\"), name);
if (access (result, F_OK)) if (access (result, F_OK))
{ {
free (result); _gpgme_free (result);
result = NULL; result = NULL;
} }
} }
@ -462,7 +462,7 @@ _gpgme_set_default_gpg_name (const char *name)
{ {
if (!default_gpg_name) if (!default_gpg_name)
{ {
default_gpg_name = malloc (strlen (name) + 5); default_gpg_name = _gpgme_malloc (strlen (name) + 5);
if (default_gpg_name) if (default_gpg_name)
{ {
strcpy (stpcpy (default_gpg_name, name), ".exe"); strcpy (stpcpy (default_gpg_name, name), ".exe");
@ -479,7 +479,7 @@ _gpgme_set_default_gpgconf_name (const char *name)
{ {
if (!default_gpgconf_name) if (!default_gpgconf_name)
{ {
default_gpgconf_name = malloc (strlen (name) + 5); default_gpgconf_name = _gpgme_malloc (strlen (name) + 5);
if (default_gpgconf_name) if (default_gpgconf_name)
{ {
strcpy (stpcpy (default_gpgconf_name, name), ".exe"); strcpy (stpcpy (default_gpgconf_name, name), ".exe");
@ -571,7 +571,7 @@ _gpgme_get_conf_int (const char *key, int *value)
if (!tmp) if (!tmp)
return 0; return 0;
*value = atoi (tmp); *value = atoi (tmp);
free (tmp); _gpgme_free (tmp);
return 1; 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) if (!tmpname)
return -1; return -1;
strcpy (stpcpy (tmpname, tmp), "\\gpgme-XXXXXX"); strcpy (stpcpy (tmpname, tmp), "\\gpgme-XXXXXX");
*fd = mkstemp (tmpname); *fd = mkstemp (tmpname);
if (fd < 0) if (fd < 0)
{ {
free (tmpname); _gpgme_free (tmpname);
return -1; return -1;
} }
@ -734,7 +734,7 @@ _gpgme_w32ce_get_debug_envvar (void)
tmp = read_w32_registry_string (NULL, "\\Software\\GNU\\gpgme", "debug"); tmp = read_w32_registry_string (NULL, "\\Software\\GNU\\gpgme", "debug");
if (tmp && !*tmp) if (tmp && !*tmp)
{ {
free (tmp); _gpgme_free (tmp);
tmp = NULL; tmp = NULL;
} }
return tmp; return tmp;

View File

@ -35,6 +35,7 @@
#include "priv-io.h" #include "priv-io.h"
#include "ops.h" #include "ops.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
/* The global event loop is used for all asynchronous operations /* The global event loop is used for all asynchronous operations
(except key listing) for which no user I/O callbacks are specified. (except key listing) for which no user I/O callbacks are specified.
@ -95,7 +96,7 @@ static struct ctx_list_item *ctx_done_list;
static gpgme_error_t static gpgme_error_t
ctx_active (gpgme_ctx_t ctx) ctx_active (gpgme_ctx_t ctx)
{ {
struct ctx_list_item *li = malloc (sizeof (struct ctx_list_item)); struct ctx_list_item *li = _gpgme_malloc (sizeof (struct ctx_list_item));
if (!li) if (!li)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
li->ctx = ctx; li->ctx = ctx;
@ -177,7 +178,7 @@ ctx_wait (gpgme_ctx_t ctx, gpgme_error_t *status, gpgme_error_t *op_err)
li->prev->next = li->next; li->prev->next = li->next;
else else
ctx_done_list = li->next; ctx_done_list = li->next;
free (li); _gpgme_free (li);
} }
else else
ctx = NULL; ctx = NULL;
@ -266,7 +267,7 @@ gpgme_wait_ext (gpgme_ctx_t ctx, gpgme_error_t *status,
LOCK (ctx_list_lock); LOCK (ctx_list_lock);
for (li = ctx_active_list; li; li = li->next) for (li = ctx_active_list; li; li = li->next)
i += li->ctx->fdt.size; i += li->ctx->fdt.size;
fdt.fds = malloc (i * sizeof (struct io_select_fd_s)); fdt.fds = _gpgme_malloc (i * sizeof (struct io_select_fd_s));
if (!fdt.fds) if (!fdt.fds)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
@ -291,7 +292,7 @@ gpgme_wait_ext (gpgme_ctx_t ctx, gpgme_error_t *status,
if (nr < 0) if (nr < 0)
{ {
int saved_err = gpg_error_from_syserror (); int saved_err = gpg_error_from_syserror ();
free (fdt.fds); _gpgme_free (fdt.fds);
if (status) if (status)
*status = saved_err; *status = saved_err;
if (op_err) if (op_err)
@ -336,7 +337,7 @@ gpgme_wait_ext (gpgme_ctx_t ctx, gpgme_error_t *status,
} }
} }
} }
free (fdt.fds); _gpgme_free (fdt.fds);
/* Now some contexts might have finished successfully. */ /* Now some contexts might have finished successfully. */
LOCK (ctx_list_lock); LOCK (ctx_list_lock);

View File

@ -38,6 +38,7 @@
#include "priv-io.h" #include "priv-io.h"
#include "engine.h" #include "engine.h"
#include "debug.h" #include "debug.h"
#include "mem.h"
void void
@ -51,7 +52,7 @@ void
_gpgme_fd_table_deinit (fd_table_t fdt) _gpgme_fd_table_deinit (fd_table_t fdt)
{ {
if (fdt->fds) if (fdt->fds)
free (fdt->fds); _gpgme_free (fdt->fds);
} }
@ -70,7 +71,7 @@ fd_table_put (fd_table_t fdt, int fd, int dir, void *opaque, int *idx)
if (i == fdt->size) if (i == fdt->size)
{ {
#define FDT_ALLOCSIZE 10 #define FDT_ALLOCSIZE 10
new_fds = realloc (fdt->fds, (fdt->size + FDT_ALLOCSIZE) new_fds = _gpgme_realloc (fdt->fds, (fdt->size + FDT_ALLOCSIZE)
* sizeof (*new_fds)); * sizeof (*new_fds));
if (!new_fds) if (!new_fds)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
@ -111,16 +112,16 @@ _gpgme_add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
fdt = &ctx->fdt; fdt = &ctx->fdt;
assert (fdt); assert (fdt);
tag = malloc (sizeof *tag); tag = _gpgme_malloc (sizeof *tag);
if (!tag) if (!tag)
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
tag->ctx = ctx; tag->ctx = ctx;
/* Allocate a structure to hold information about the handler. */ /* Allocate a structure to hold information about the handler. */
item = calloc (1, sizeof *item); item = _gpgme_calloc (1, sizeof *item);
if (!item) if (!item)
{ {
free (tag); _gpgme_free (tag);
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
} }
item->ctx = ctx; item->ctx = ctx;
@ -131,8 +132,8 @@ _gpgme_add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
err = fd_table_put (fdt, fd, dir, item, &tag->idx); err = fd_table_put (fdt, fd, dir, item, &tag->idx);
if (err) if (err)
{ {
free (tag); _gpgme_free (tag);
free (item); _gpgme_free (item);
return err; return err;
} }
@ -163,8 +164,8 @@ _gpgme_remove_io_cb (void *data)
"setting fd 0x%x (item=%p) done", fdt->fds[idx].fd, "setting fd 0x%x (item=%p) done", fdt->fds[idx].fd,
fdt->fds[idx].opaque); fdt->fds[idx].opaque);
free (fdt->fds[idx].opaque); _gpgme_free (fdt->fds[idx].opaque);
free (tag); _gpgme_free (tag);
/* Free the table entry. */ /* Free the table entry. */
fdt->fds[idx].fd = -1; fdt->fds[idx].fd = -1;