bin/159011: Memory leak in bin/ed/buf.c

Henning Petersen henning.petersen at t-online.de
Mon Jul 18 16:10:10 UTC 2011


>Number:         159011
>Category:       bin
>Synopsis:       Memory leak in bin/ed/buf.c
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 18 16:10:09 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Henning Petersen
>Release:        FreeBSD-current
>Organization:
>Environment:
>Description:
Memory leak in bin/ed/buf.c .
>How-To-Repeat:

>Fix:
diff -u -r1.22 buf.c
--- bin/ed/buf.c	30 Jun 2002 05:13:53 -0000	1.22
+++ bin/ed/buf.c	18 Jul 2011 13:19:28 -0000
@@ -94,6 +94,7 @@
 		;
 	if (s - cs >= LINECHARS) {
 		errmsg = "line too long";
+		free(lp);
 		return NULL;
 	}
 	len = s - cs;
@@ -102,6 +103,7 @@
 		if (fseeko(sfp, (off_t)0, SEEK_END) < 0) {
 			fprintf(stderr, "%s\n", strerror(errno));
 			errmsg = "cannot seek temp file";
+			free(lp);
 			return NULL;
 		}
 		sfseek = ftello(sfp);
@@ -112,6 +114,7 @@
 		sfseek = -1;
 		fprintf(stderr, "%s\n", strerror(errno));
 		errmsg = "cannot write temp file";
+		free(lp);
 		return NULL;
 	}
 	lp->len = len;


Patch attached with submission follows:

diff -u -r1.22 buf.c
--- bin/ed/buf.c	30 Jun 2002 05:13:53 -0000	1.22
+++ bin/ed/buf.c	18 Jul 2011 13:19:28 -0000
@@ -94,6 +94,7 @@
 		;
 	if (s - cs >= LINECHARS) {
 		errmsg = "line too long";
+		free(lp);
 		return NULL;
 	}
 	len = s - cs;
@@ -102,6 +103,7 @@
 		if (fseeko(sfp, (off_t)0, SEEK_END) < 0) {
 			fprintf(stderr, "%s\n", strerror(errno));
 			errmsg = "cannot seek temp file";
+			free(lp);
 			return NULL;
 		}
 		sfseek = ftello(sfp);
@@ -112,6 +114,7 @@
 		sfseek = -1;
 		fprintf(stderr, "%s\n", strerror(errno));
 		errmsg = "cannot write temp file";
+		free(lp);
 		return NULL;
 	}
 	lp->len = len;


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list