NetBSD-Bugs archive

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

bin/39721: Memory leak in exception branch of the curdir_push function in usr.bin/config/scan.l



>Number:         39721
>Category:       bin
>Synopsis:       Memory leak in exception branch of the curdir_push function in 
>usr.bin/config/scan.l
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 09 04:20:01 +0000 2008
>Originator:     Gao Ya'nan
>Release:        NetBSD-current and NetBSD-4.0
>Organization:
>Environment:
NetBSD abutter.foo.org 4.0 NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:20:10 PST 
2007  
builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/GENERIC
 i386
>Description:
----------------------------------->cut<----------------------------------------
static int
curdir_push(const char *fname)
{
        struct prefix *pf;
        char *p, *d, *f;

        /* Set up the initial "current directory" for include directives. */
        d = dirname(f = estrdup(fname));
        if (*d == '/')
                p = estrdup(d);
        else {
                char *cwd, buf[PATH_MAX];

                if ((cwd = getcwd(buf, sizeof(buf))) == NULL)
                        return (-1);
                p = emalloc(strlen(cwd) + strlen(d) + 2);
                sprintf(p, "%s/%s", cwd, d);
        }
        free(f);
----------------------------------->cut<----------------------------------------

When everything goes well, f will be freed, but not when the getcwd fails.
>How-To-Repeat:
Review the code
>Fix:
free f in exception branch as well



Home | Main Index | Thread Index | Old Index