Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 4e540d3b86ae3cb0893f409e5be32cab > files > 6

procps-3.2.8-8.fc13.src.rpm

--- procps-3.2.7/proc/readproc.c.kzak	2006-06-16 10:18:13.000000000 +0200
+++ procps-3.2.7/proc/readproc.c	2006-09-27 11:25:13.000000000 +0200
@@ -432,14 +432,17 @@
     if(fd==-1) return NULL;
 
     /* read whole file into a memory buffer, allocating as we go */
-    while ((n = read(fd, buf, sizeof buf - 1)) > 0) {
+    while ((n = read(fd, buf, sizeof buf - 1)) >= 0) {
 	if (n < (int)(sizeof buf - 1))
 	    end_of_file = 1;
-	if (n == 0 && rbuf == 0)
+	if (n == 0 && rbuf == 0) {
+	    close(fd);
 	    return NULL;	/* process died between our open and read */
+	}
 	if (n < 0) {
 	    if (rbuf)
 		free(rbuf);
+	    close(fd);
 	    return NULL;	/* read error */
 	}
 	if (end_of_file && buf[n-1])		/* last read char not null */