FD leak fix in volume_id.c

Kay Sievers kay.sievers at vrfy.org
Thu May 27 16:43:58 PDT 2004


On Thu, May 27, 2004 at 09:02:03PM +0200, David Zeuthen wrote:
> On Sat, 2004-05-22 at 18:31 +0100, Crispin Flowerday wrote:
> > Hi,
> > 
> 
> Hi,
> 
> Sorry for the lag, your message was in the moderation queue since you
> are not subscribed
> 
> > While debugging the file descriptor leak that stops cdroms being
> > ejected, I noticed a theoretical file descriptor when the box runs out
> > of memory:
> > 
> 
> Nice catch, applied, thanks. Kay, you probably want to apply this in
> your udev program that uses the same sources.

Sharp eyes, Crispin :)

Yeah, I prepared it this afternoon, but stumbled accross the partition
bug. So here is the missing part for the paranoid, which includes the pid
in the temporary device node, in the case someone runs the same code in
parallel.

thanks,
Kay
-------------- next part --------------
Index: hald/linux/volume_id/volume_id.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/volume_id/volume_id.c,v
retrieving revision 1.4
diff -u -r1.4 volume_id.c
--- a/hald/linux/volume_id/volume_id.c	27 May 2004 19:13:39 -0000	1.4
+++ b/hald/linux/volume_id/volume_id.c	27 May 2004 23:34:25 -0000
@@ -82,7 +82,7 @@
 	memcpy(id->label_string, buf, count);
 
 	/* remove trailing whitespace */
-	i = strlen(id->label_string);
+	i = strnlen(id->label_string, count);
 	while (i--) {
 		if (! isspace(id->label_string[i]))
 			break;
@@ -841,10 +841,11 @@
 	char tmp_node[VOLUME_ID_PATH_MAX];
 
 	snprintf(tmp_node, VOLUME_ID_PATH_MAX,
-		 "/tmp/volume-%u-%u", major(devt), minor(devt));
+		 "/tmp/volume-%u-%u-%u", getpid(), major(devt), minor(devt));
 	tmp_node[VOLUME_ID_PATH_MAX] = '\0';
 
 	/* create tempory node to open the block device */
+	unlink(tmp_node);
 	if (mknod(tmp_node, (S_IFBLK | 0600), devt) != 0)
 		return NULL;
 
Index: hald/linux/volume_id/volume_id.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/volume_id/volume_id.h,v
retrieving revision 1.2
diff -u -r1.2 volume_id.h
--- a/hald/linux/volume_id/volume_id.h	4 May 2004 21:56:47 -0000	1.2
+++ b/hald/linux/volume_id/volume_id.h	27 May 2004 23:34:25 -0000
@@ -21,7 +21,7 @@
 #ifndef _VOLUME_ID_H_
 #define _VOLUME_ID_H_
 
-#define VOLUME_ID_VERSION		002
+#define VOLUME_ID_VERSION		003
 
 #define VOLUME_ID_LABEL_SIZE		32
 #define VOLUME_ID_UUID_SIZE		16
-------------- next part --------------
_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal


More information about the Hal mailing list