FD leak fix in volume_id.c

Crispin Flowerday gnome at flowerday.cx
Sat May 22 10:31:18 PDT 2004


Hi,

While debugging the file descriptor leak that stops cdroms being
ejected, I noticed a theoretical file descriptor when the box runs out
of memory:

Index: linux/volume_id/volume_id.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/volume_id/volume_id.c,v
retrieving revision 1.3
diff -u -u -8 -r1.3 volume_id.c
--- a/linux/volume_id/volume_id.c	5 May 2004 05:02:30 -0000	1.3
+++ b/linux/volume_id/volume_id.c	22 May 2004 17:23:37 -0000
@@ -818,18 +818,20 @@
 	struct volume_id *id;
 	int fd;
 
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
 		return NULL;
 
 	id = volume_id_open_fd(fd);
-	if (id == NULL)
+	if (id == NULL) {
+		close (fd);
 		return NULL;
+        }
 
 	/* close fd on device close */
 	id->fd_close = 1;
 
 	return id;
 }
 
 /* open volume by major/minor */


Crispin


_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal



More information about the Hal mailing list