diff options
author | Werner Koch <wk@gnupg.org> | 2011-04-01 10:16:31 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2011-04-01 10:16:31 +0200 |
commit | 934d270ff8193a5931b143ce850f66f50d03dedf (patch) | |
tree | bf80b5ebadafa34805e1323ca67f50001fa4ea67 /src | |
parent | ec033383618c4b3739783d31ca4dc70c9bb4fcfe (diff) | |
download | libgcrypt-934d270ff8193a5931b143ce850f66f50d03dedf.tar.gz |
Make sure that gcry_realloc (NULL, n) works on all platforms.
realloc (NULL, n) shall behave exactly like malloc (n)
and realloc (p, 0) like free.
Not all platforms implement this correctly thus we now handle this
directly in gcry_realloc.
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 4 | ||||
-rw-r--r-- | src/global.c | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 9ef6c5d7..9476e82e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2011-04-01 Werner Koch <wk@g10code.com> + + * global.c (gcry_realloc): Divert to gcry_malloc or gcry_free. + 2011-03-09 Werner Koch <wk@g10code.com> * gcrypt.h.in (gcry_kdf_algos): New. diff --git a/src/global.c b/src/global.c index cbb7eb89..d65b0680 100644 --- a/src/global.c +++ b/src/global.c @@ -833,6 +833,16 @@ gcry_realloc (void *a, size_t n) { void *p; + /* To avoid problems with non-standard realloc implementations and + our own secmem_realloc, we divert to malloc and free here. */ + if (!a) + return gcry_malloc (n); + if (!n) + { + gcry_free (a); + return NULL; + } + if (realloc_func) p = realloc_func (a, n); else |