libgcrypt/Fix-memory-leak-in-secmem-in-out-of-core-conditions.patch
2019-09-30 10:56:07 -04:00

35 lines
1.1 KiB
Diff

From f74687fd43f5772a372f54031d5a9527597f4ce4 Mon Sep 17 00:00:00 2001
From: Werner Koch <wk@gnupg.org>
Date: Wed, 24 Oct 2018 11:55:34 +0200
Subject: [PATCH 098/152] Fix memory leak in secmem in out of core conditions.
* src/secmem.c (_gcry_secmem_malloc_internal): Release pool descriptor
if the pool could not be allocated.
--
GnuPG-bug-id: 4211
Signed-off-by: Werner Koch <wk@gnupg.org>
---
src/secmem.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/secmem.c b/src/secmem.c
index 79c135f..3e091d8 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -658,7 +658,10 @@ _gcry_secmem_malloc_internal (size_t size, int xhint)
pool->size = auto_expand? auto_expand : STANDARD_POOL_SIZE;
pool->mem = malloc (pool->size);
if (!pool->mem)
- return NULL; /* Not enough memory available for a new pool. */
+ {
+ free (pool);
+ return NULL; /* Not enough memory available for a new pool. */
+ }
/* Initialize first memory block. */
mb = (memblock_t *) pool->mem;
mb->size = pool->size - BLOCK_HEAD_SIZE;
--
1.8.3.1