[Bug 203647] makefs: Coverity CID 978431: No free() after malloc().

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Oct 8 19:04:28 UTC 2015


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203647

            Bug ID: 203647
           Summary: makefs: Coverity CID 978431: No free() after malloc().
           Product: Base System
           Version: 11.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: freebsd-bugs at FreeBSD.org
          Reporter: scdbackup at gmx.net

usr.sbin/makefs/cd9660/cd9660_write.c

CID 978431: Resource leak (RESOURCE_LEAK)
   9. leaked_storage: Variable buffer going out of scope leaks the
   storage it points to.

216        return cd9660_write_filedata(fd, sector, buffer_head,
217            path_table_sectors);

--------------- Source analysis:

There are two return statements in the function.
The first one (return 0) is ok, because malloc() returned NULL.
The second one uses the allocated buffer and does not free it.

--------------- Remedy proposal:

Untangle the return statement.

-        return cd9660_write_filedata(fd, sector, buffer_head,
+        ret = cd9660_write_filedata(fd, sector, buffer_head,
              path_table_sectors);
+        free(buffer);
+        return ret;

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list