commit:     98db340d61a9607ab179a5d4dc057cf453d90e55
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue Sep 15 18:21:29 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Tue Sep 15 18:21:29 2015 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=98db340d

libsandbox: avoid leaking memory when extracting strings

If userland supports process_vm_readv, but the kernel does not (newer
kernel headers & C lib than kernel), then we leak a bit of memory when
we fallback to the ptrace code.  Do not re-allocate the ret buffer if
the code does fallback.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

 libsandbox/trace.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libsandbox/trace.c b/libsandbox/trace.c
index dfbab18..1d40392 100644
--- a/libsandbox/trace.c
+++ b/libsandbox/trace.c
@@ -119,11 +119,12 @@ static char *do_peekstr(unsigned long lptr)
                ret = xrealloc(ret, len);
                liov.iov_base = ret + len - l;
        }
+#else
+       len = 1024;
+       ret = xmalloc(len);
 #endif
 
        l = 0;
-       len = 1024;
-       ret = xmalloc(len);
        while (1) {
                a = lptr & (sizeof(long) - 1);
                lptr -= a;

Reply via email to