[patch] fix fd leak when checking mtab

Sjoerd Simons sjoerd at luon.net
Fri May 21 02:02:42 PDT 2004


Hi,

  hal doesn't close the filedescriptor when it /etc/mtab wasn't changed of the
  fstat failed.

  Also when closing a file stream opened with fdopen, the original fd is also
  closed (the fdopen function doesn't dup the fd). So the close after fclose 
  is wrong. 

  Attached patch fixes these things.

  Sjoerd
-- 
We gave you an atomic bomb, what do you want, mermaids?
		-- I. I. Rabi to the Atomic Energy Commission
-------------- next part --------------
Index: hald/linux/block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.22
diff -u -r1.22 block_class_device.c
--- a/hald/linux/block_class_device.c	13 May 2004 21:21:32 -0000	1.22
+++ b/hald/linux/block_class_device.c	21 May 2004 07:10:39 -0000
@@ -1268,11 +1268,13 @@
 
 	if (fstat (fd, &stat_buf) != 0) {
 		HAL_ERROR (("Cannot fstat /etc/mtab fd, errno=%d", errno));
+		close(fd);
 		return FALSE;
 	}
 
 	if (!force && etc_mtab_mtime == stat_buf.st_mtime) {
 		/*printf("No modification, etc_mtab_mtime=%d\n", etc_mtab_mtime); */
+		close(fd);
 		return FALSE;
 	}
 
@@ -1295,9 +1297,6 @@
 	}
 
 	fclose (f);
-
-	close (fd);
-
 	return TRUE;
 }
 
-------------- next part --------------
_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal


More information about the Hal mailing list