Date: Thu, 22 Sep 2005 22:07:54 +1200 (NZST) From: Andrew Turner <andrew@fubar.geek.nz> To: FreeBSD-gnats-submit@FreeBSD.org Cc: Tim Kientzle <kientzle@FreeBSD.org> Subject: bin/86453: libarchive memory leak with bad fd Message-ID: <20050922100754.9807B6163@serv.int.fubar.geek.nz> Resent-Message-ID: <200509221010.j8MAABTo079215@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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@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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050922100754.9807B6163>