Module Name:    src
Committed By:   snj
Date:           Thu Apr 23 02:03:55 UTC 2009

Modified Files:
        src/lib/libedit [netbsd-3]: term.c

Log Message:
Apply patch (requested by msaitoh in ticket #2007):
Coverity CID 1668: Plug memory leak when malloc() failed.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.40.2.1 src/lib/libedit/term.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/libedit/term.c
diff -u src/lib/libedit/term.c:1.40 src/lib/libedit/term.c:1.40.2.1
--- src/lib/libedit/term.c:1.40	Sat May 22 23:21:28 2004
+++ src/lib/libedit/term.c	Thu Apr 23 02:03:55 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: term.c,v 1.40 2004/05/22 23:21:28 christos Exp $	*/
+/*	$NetBSD: term.c,v 1.40.2.1 2009/04/23 02:03:55 snj Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)term.c	8.2 (Berkeley) 4/30/95";
 #else
-__RCSID("$NetBSD: term.c,v 1.40 2004/05/22 23:21:28 christos Exp $");
+__RCSID("$NetBSD: term.c,v 1.40.2.1 2009/04/23 02:03:55 snj Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -472,8 +472,12 @@
 		return (-1);
 	for (i = 0; i < c->v; i++) {
 		b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
-		if (b[i] == NULL)
+		if (b[i] == NULL) {
+			while (--i >= 0)
+				el_free((ptr_t) b[i]);
+			el_free((ptr_t) b);
 			return (-1);
+		}
 	}
 	b[c->v] = NULL;
 	el->el_display = b;
@@ -483,8 +487,12 @@
 		return (-1);
 	for (i = 0; i < c->v; i++) {
 		b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
-		if (b[i] == NULL)
+		if (b[i] == NULL) {
+			while (--i >= 0)
+				el_free((ptr_t) b[i]);
+			el_free((ptr_t) b);
 			return (-1);
+		}
 	}
 	b[c->v] = NULL;
 	el->el_vdisplay = b;

Reply via email to