Module Name: src Committed By: christos Date: Tue Jan 26 16:05:18 UTC 2016
Modified Files: src/lib/libcompat/regexp: regexp.c Log Message: PR/50711: David Binderman: Fix memory leak on error To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libcompat/regexp/regexp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libcompat/regexp/regexp.c diff -u src/lib/libcompat/regexp/regexp.c:1.18 src/lib/libcompat/regexp/regexp.c:1.19 --- src/lib/libcompat/regexp/regexp.c:1.18 Fri Feb 16 11:34:19 2007 +++ src/lib/libcompat/regexp/regexp.c Tue Jan 26 11:05:18 2016 @@ -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 @@ const char *expn; 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 @@ const char *expn; 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. */