bin/86453: libarchive memory leak with bad fd
Andrew Turner
andrew at fubar.geek.nz
Thu Sep 22 03:10:13 PDT 2005
>Number: 86453
>Category: bin
>Synopsis: libarchive memory leak with bad fd
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Sep 22 10:10:11 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Andrew Turner
>Release: FreeBSD 5.4-STABLE i386
>Organization:
>Environment:
System: FreeBSD serv.int.fubar.geek.nz 5.4-STABLE FreeBSD 5.4-STABLE #7: Wed May 11 23:57:29 NZST 2005 root at serv.int.fubar.geek.nz:/usr/obj/srctrees/RELENG_5/sys/GENERIC i386
>Description:
archive_read_open_fd dosn't free the client data if fstat fails.
This can cause a memory leak as file_close is not called later to free the data.
>How-To-Repeat:
The following code leaks the client data as file_close from archive_read_open_fd.c is never called.
#include <archive.h>
int main (int argc, char *argv[]) {
struct archive *a;
int i;
a = archive_read_new();
archive_read_support_compression_all(a);
archive_read_open_fd(a, -1, 1024);
archive_read_finish(a);
}
>Fix:
This patch fixed the leak by freeing the client data when fstat fails.
--- libarchive_ngtve_fd.diff begins here ---
Index: archive_read_open_fd.c
===================================================================
RCS file: /cvsroot/src/lib/libarchive/archive_read_open_fd.c,v
retrieving revision 1.4
diff -u -3 -p -u -r1.4 archive_read_open_fd.c
--- archive_read_open_fd.c 21 Sep 2005 04:25:05 -0000 1.4
+++ archive_read_open_fd.c 22 Sep 2005 09:57:30 -0000
@@ -75,6 +75,8 @@ file_open(struct archive *a, void *clien
if (fstat(mine->fd, &st) != 0) {
archive_set_error(a, errno, "Can't stat fd %d", mine->fd);
+ free(mine->buffer);
+ free(mine);
return (ARCHIVE_FATAL);
}
--- libarchive_ngtve_fd.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list