[PATCH] Avoid secmem leaking capability state
Mike Crowe
mac at mcrowe.com
Fri Nov 22 13:31:06 CET 2013
The capability state returned by cap_from_text needs to be freed after it
has been used.
Valgrind reports this as:
36 bytes in 1 blocks are definitely lost in loss record 132 of 242
at 0x4027938: malloc (vg_replace_malloc.c:270)
by 0x4C0B2CF: cap_init (cap_alloc.c:19)
by 0x4C0BE0F: cap_from_text (cap_text.c:122)
by 0x4573413: secmem_init (secmem.c:243)
by 0x4573691: _gcry_secmem_malloc_internal (secmem.c:517)
by 0x4573869: _gcry_secmem_malloc (secmem.c:554)
by 0x4573007: _gcry_private_malloc_secure (stdmem.c:147)
by 0x456F0F4: do_malloc.constprop.4 (global.c:774)
by 0x456FAEF: _gcry_malloc_secure (global.c:813)
by 0x45841AB: md_open (md.c:491)
by 0x4584861: _gcry_md_open (md.c:534)
by 0x456D1D8: gcry_md_open (visibility.c:777)
36 bytes in 1 blocks are definitely lost in loss record 133 of 242
at 0x4027938: malloc (vg_replace_malloc.c:270)
by 0x4C0B2CF: cap_init (cap_alloc.c:19)
by 0x4C0BE0F: cap_from_text (cap_text.c:122)
by 0x4573505: secmem_init (secmem.c:247)
by 0x4573691: _gcry_secmem_malloc_internal (secmem.c:517)
by 0x4573869: _gcry_secmem_malloc (secmem.c:554)
by 0x4573007: _gcry_private_malloc_secure (stdmem.c:147)
by 0x456F0F4: do_malloc.constprop.4 (global.c:774)
by 0x456FAEF: _gcry_malloc_secure (global.c:813)
by 0x45841AB: md_open (md.c:491)
by 0x4584861: _gcry_md_open (md.c:534)
by 0x456D1D8: gcry_md_open (visibility.c:777)
Signed-off-by: Mike Crowe <mac at mcrowe.com>
---
src/secmem.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/secmem.c b/src/secmem.c
index c350bc9..2d76858 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -242,12 +242,17 @@ lock_pool (void *p, size_t n)
{
#if defined(USE_CAPABILITIES) && defined(HAVE_MLOCK)
int err;
+ cap_t cap;
- cap_set_proc (cap_from_text ("cap_ipc_lock+ep"));
+ cap = cap_from_text ("cap_ipc_lock+ep");
+ cap_set_proc (cap);
+ cap_free(cap);
err = no_mlock? 0 : mlock (p, n);
if (err && errno)
err = errno;
- cap_set_proc (cap_from_text ("cap_ipc_lock+p"));
+ cap = cap_from_text ("cap_ipc_lock+p");
+ cap_set_proc (cap);
+ cap_free(cap);
if (err)
{
--
1.7.10.4
More information about the Gcrypt-devel
mailing list