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

Bug#439029: libapt leaks file descriptors



Package: libapt
Severity: important
Tags: patch


repeated calls to libapt results in leaking file descriptors, this
only causes a serious problem if you are doing an entire mirrors
worth.  It does NOT leak one FD per .deb file processed.  

I discovered this when I collected all the checksums from a mirror
for tripwire like usage, for example after processing a few
hundred files I get the following:
etch:~# ls -al /proc/2348/fd
total 15
dr-x------ 2 root root  0 Aug 21 18:24 .
dr-xr-xr-x 5 root root  0 Aug 21 18:24 ..
lrwx------ 1 root root 64 Aug 21 18:24 0 -> /dev/ttyp3
lrwx------ 1 root root 64 Aug 21 18:24 1 -> /dev/ttyp3
l-wx------ 1 root root 64 Aug 21 18:25 10 -> /tmp/cdr/gDrBVM.cdr/usr/lib/perl/5.8.8/auto/Fcntl/Fcntl.bs (deleted)
l-wx------ 1 root root 64 Aug 21 18:25 11 -> /tmp/cdr/gDrBVM.cdr/usr/lib/perl/5.8.8/auto/File/Glob/Glob.bs (deleted)
l-wx------ 1 root root 64 Aug 21 18:25 12 -> /tmp/cdr/gDrBVM.cdr/usr/lib/perl/5.8.8/auto/IO/IO.bs (deleted)
l-wx------ 1 root root 64 Aug 21 18:25 13 -> /tmp/cdr/gDrBVM.cdr/usr/lib/perl/5.8.8/auto/List/Util/Util.bs (deleted)
l-wx------ 1 root root 64 Aug 21 18:25 14 -> /tmp/cdr/gDrBVM.cdr/usr/lib/perl/5.8.8/auto/POSIX/POSIX.bs (deleted)
l-wx------ 1 root root 64 Aug 21 18:25 15 -> /tmp/cdr/gDrBVM.cdr/usr/lib/perl/5.8.8/auto/Socket/Socket.bs (deleted)
lrwx------ 1 root root 64 Aug 21 18:24 2 -> /dev/ttyp3
....

Michael Vogt wrote the following patch which I tested and it works:
=== modified file 'apt-inst/contrib/extracttar.cc'
--- apt-inst/contrib/extracttar.cc	2007-06-08 23:44:03 +0000
+++ apt-inst/contrib/extracttar.cc	2007-08-02 09:53:25 +0000
@@ -332,7 +332,7 @@
       }
       
       // And finish up
-      if (Itm.Size != 0 && BadRecord == false)
+      if (Itm.Size >= 0 && BadRecord == false)
 	 if (Stream.FinishedFile(Itm,Fd) == false)
 	    return false;
       

=== modified file 'debian/changelog'
--- debian/changelog	2007-08-01 22:51:20 +0000
+++ debian/changelog	2007-08-02 09:56:27 +0000
@@ -1,3 +1,10 @@
+apt (0.7.7) UNRELEASED; urgency=low
+
+  * apt-inst/contrib/extracttar.cc:
+    - fix fd leak for zero size files 
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 02 Aug 2007 11:55:54 +0200
+
 apt (0.7.6) unstable; urgency=low
 
   * Applied patch from Aurelien Jarno <aurel32@debian.org> to fix wrong


-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.16.33-xen
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
ANSI_X3.4-1968)
=== modified file 'apt-inst/contrib/extracttar.cc'
--- apt-inst/contrib/extracttar.cc	2007-06-08 23:44:03 +0000
+++ apt-inst/contrib/extracttar.cc	2007-08-02 09:53:25 +0000
@@ -332,7 +332,7 @@
       }
       
       // And finish up
-      if (Itm.Size != 0 && BadRecord == false)
+      if (Itm.Size >= 0 && BadRecord == false)
 	 if (Stream.FinishedFile(Itm,Fd) == false)
 	    return false;
       

=== modified file 'debian/changelog'
--- debian/changelog	2007-08-01 22:51:20 +0000
+++ debian/changelog	2007-08-02 09:56:27 +0000
@@ -1,3 +1,10 @@
+apt (0.7.7) UNRELEASED; urgency=low
+
+  * apt-inst/contrib/extracttar.cc:
+    - fix fd leak for zero size files 
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 02 Aug 2007 11:55:54 +0200
+
 apt (0.7.6) unstable; urgency=low
 
   * Applied patch from Aurelien Jarno <aurel32@debian.org> to fix wrong


Reply to: