summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2011-04-01 10:16:31 +0200
committerWerner Koch <wk@gnupg.org>2011-04-01 10:16:31 +0200
commit934d270ff8193a5931b143ce850f66f50d03dedf (patch)
treebf80b5ebadafa34805e1323ca67f50001fa4ea67 /src
parentec033383618c4b3739783d31ca4dc70c9bb4fcfe (diff)
downloadlibgcrypt-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/ChangeLog4
-rw-r--r--src/global.c10
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