NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/45843: Resource leak in vi.c.



>Number:         45843
>Category:       lib
>Synopsis:       Resource leak in vi.c.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 16 11:50:00 +0000 2012
>Originator:     Henning Petersen
>Release:        NetBSD-current
>Organization:
>Environment:
>Description:
Resource leak in error path.
In case cp == NULL change order of close and unlink.
>How-To-Repeat:

>Fix:
diff -u -p -r1.42 vi.c
--- lib/libedit/vi.c    18 Nov 2011 20:24:21 -0000      1.42
+++ lib/libedit/vi.c    16 Jan 2012 10:50:00 -0000
@@ -1022,13 +1022,15 @@ vi_histedit(EditLine *el, Int c __attrib
 #define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
        cp = el_malloc(TMP_BUFSIZ * sizeof(*cp));
        if (cp == NULL) {
-               unlink(tempfile);
                close(fd);
+               unlink(tempfile);
                return CC_ERROR;
        }
        line = el_malloc(len * sizeof(*line) + 1);
        if (line == NULL) {
+               close(fd);
+               unlink(tempfile);
                el_free(cp);
                return CC_ERROR;
        }
        Strncpy(line, el->el_line.buffer, len);



Home | Main Index | Thread Index | Old Index