summaryrefslogtreecommitdiff
path: root/src/secmem.c
diff options
context:
space:
mode:
authorMoritz Schulte <mo@g10code.com>2003-09-28 03:08:43 +0000
committerMoritz Schulte <mo@g10code.com>2003-09-28 03:08:43 +0000
commitb71be47fdd4033be2a80f0c3b2790a3e2a6dedb4 (patch)
treed26288b467fb71a53c885d267a06d58058932990 /src/secmem.c
parent3eae8e02a52ed98eafd841c5a081457ef46a7320 (diff)
downloadlibgcrypt-b71be47fdd4033be2a80f0c3b2790a3e2a6dedb4.tar.gz
2003-09-28 Moritz Schulte <mo@g10code.com>
* secmem.c (_gcry_secmem_realloc): Do not forget to release secmem lock. Thanks to low halo for triggering this bug.
Diffstat (limited to 'src/secmem.c')
-rw-r--r--src/secmem.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/secmem.c b/src/secmem.c
index 0d038ae3..425aa2bc 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -542,13 +542,20 @@ _gcry_secmem_realloc (void *p, size_t newsize)
mb = (memblock_t *) ((char *) p - ((size_t) &((memblock_t *) 0)->aligned.c));
size = mb->size;
if (newsize < size)
- return p; /* it is easier not to shrink the memory */
- a = _gcry_secmem_malloc_internal (newsize);
- if (a)
{
- memcpy (a, p, size);
- memset ((char *) a + size, 0, newsize - size);
- _gcry_secmem_free_internal (p);
+ SECMEM_UNLOCK;
+ /* It is easier to not shrink the memory. */
+ a = p;
+ }
+ else
+ {
+ a = _gcry_secmem_malloc_internal (newsize);
+ if (a)
+ {
+ memcpy (a, p, size);
+ memset ((char *) a + size, 0, newsize - size);
+ _gcry_secmem_free_internal (p);
+ }
}
SECMEM_UNLOCK;