summaryrefslogtreecommitdiff
path: root/lib/libcompat
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2016-01-26 16:05:18 +0000
committerchristos <christos@NetBSD.org>2016-01-26 16:05:18 +0000
commit3fc8b43d104a7aad68cdcd0043ce620db7db3d09 (patch)
treeeae52d39836cf1b80ba0b31366fc8ea6e20d0d11 /lib/libcompat
parent6ffbb5c12bd8571507909d2ff6429ccade7874c2 (diff)
PR/50711: David Binderman: Fix memory leak on error
Diffstat (limited to 'lib/libcompat')
-rw-r--r--lib/libcompat/regexp/regexp.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libcompat/regexp/regexp.c b/lib/libcompat/regexp/regexp.c
index 6667b854552..97a0e8dff96 100644
--- a/lib/libcompat/regexp/regexp.c
+++ b/lib/libcompat/regexp/regexp.c
@@ -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. */