Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcompat/regexp PR/50711: David Binderman: Fix memory l...



details:   https://anonhg.NetBSD.org/src/rev/7fac937d6e14
branches:  trunk
changeset: 343250:7fac937d6e14
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Jan 26 16:05:18 2016 +0000

description:
PR/50711: David Binderman: Fix memory leak on error

diffstat:

 lib/libcompat/regexp/regexp.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (33 lines):

diff -r eb5ef9377118 -r 7fac937d6e14 lib/libcompat/regexp/regexp.c
--- a/lib/libcompat/regexp/regexp.c     Tue Jan 26 16:04:12 2016 +0000
+++ b/lib/libcompat/regexp/regexp.c     Tue Jan 26 16:05:18 2016 +0000
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: regexp.c,v 1.18 2007/02/16 16:34:19 freza Exp $");
+__RCSID("$NetBSD: regexp.c,v 1.19 2016/01/26 16:05:18 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include <ctype.h>
@@ -236,7 +236,7 @@
                FAIL("regexp too big");
 
        /* Allocate space. */
-       r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize);
+       r = malloc(sizeof(regexp) + (unsigned)regsize);
        if (r == NULL)
                FAIL("out of space");
 
@@ -246,8 +246,10 @@
        regnpar = 1;
        regcode = r->program;
        regc(MAGIC);
-       if (reg(0, &flags) == NULL)
+       if (reg(0, &flags) == NULL) {
+               free(r);
                return(NULL);
+       }
 
        /* Dig out information for optimizations. */
        r->regstart = '\0';     /* Worst-case defaults. */



Home | Main Index | Thread Index | Old Index