Subject: bin/22694: plug memory leak in src/bin/ed/buf.c
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <marchand_latifi.patrick@courrier.uqam.ca>
List: netbsd-bugs
Date: 09/05/2003 14:48:15
>Number:         22694
>Category:       bin
>Synopsis:       plug memory leak in src/bin/ed/buf.c
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 05 14:49:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Patrick Latifi
>Release:        -current
>Organization:
>Environment:
netbsd
>Description:
* plug memory leak if put_sbuf_line() fails.
>How-To-Repeat:

>Fix:
Index: buf.c
===================================================================
RCS file: /cvsroot/src/bin/ed/buf.c,v
retrieving revision 1.21
diff -u -r1.21 buf.c
--- buf.c       2000/04/17 23:37:50     1.21
+++ buf.c       2003/09/05 14:44:28
@@ -108,6 +108,7 @@
                ;
        if (s - cs >= LINECHARS) {
                sprintf(errmsg, "line too long");
+               free(lp);
                return NULL;
        }
        len = s - cs;
@@ -116,6 +117,7 @@
                if (fseek(sfp, 0L, SEEK_END) < 0) {
                        fprintf(stderr, "%s\n", strerror(errno));
                        sprintf(errmsg, "cannot seek temp file");
+                       free(lp);
                        return NULL;
                }
                sfseek = ftell(sfp);
@@ -126,6 +128,7 @@
                sfseek = -1;
                fprintf(stderr, "%s\n", strerror(errno));
                sprintf(errmsg, "cannot write temp file");
+               free(lp);
                return NULL;
        }
        lp->len = len;
>Release-Note:
>Audit-Trail:
>Unformatted: