Skip to contentSkip to conversation

Don't leak a file descriptor in fcntl_lock_file(), when fcntl fails.

PATCH Jim Meyering 1 participant 1 message Jul 28, 2007

lore
Share & tools
lore
#0 lore raw

Looking at recent lvm-file.c changes, I stumbled upon a leak that's surprisingly similar to the one fixed last week in lib/locking/file_locking.c. Here's the fix:

WHATS_NEW +1 -0
index 44b1e98..243ca25 100644
@@ -1,5 +1,6 @@
 Version 2.02.28 -
 ================================
+  Don't leak a file descriptor in fcntl_lock_file(), when fcntl fails.
   Remove create_dir function; use now-equivalent dm_create_dir instead
   Detect stream write failure reliably; new fn: lvm_fclose; use dm_fclose
   Fix clvmd if compiled with gulm support. (2.02.26)
lib/misc/lvm-file.c +1 -0
index caaebbe..7ce0a0b 100644
@@ -245,6 +245,7 @@ int fcntl_lock_file(const char *file, short lock_type, int warn_if_read_only)
 
 	if (fcntl(lockfd, F_SETLKW, &lock)) {
 		log_sys_error("fcntl", file);
+		close(lockfd);
 		return -1;
 	}
 

--
1.5.3.rc3.13.g7ab3