about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSebastian Gniazdowski <psprint@zdharma.org>2017-12-30 16:32:34 +0100
committerPeter Stephenson <pws@zsh.org>2018-01-04 17:06:22 +0000
commit1e46f73b8e2e5e69dc40fd85ae83b88cccc1daf8 (patch)
tree22004e23eaf571bb59e9d6eb54e5188efc39e03e
parent21a09a14181851e931f9b2b65704044eed169fb7 (diff)
downloadzsh-1e46f73b8e2e5e69dc40fd85ae83b88cccc1daf8.tar.gz
zsh-1e46f73b8e2e5e69dc40fd85ae83b88cccc1daf8.tar.xz
zsh-1e46f73b8e2e5e69dc40fd85ae83b88cccc1daf8.zip
42188: Close flock descriptor in failure cases
-rw-r--r--ChangeLog5
-rw-r--r--Src/Modules/system.c14
2 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index d7ab6fea8..f74c26b88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-04  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* Sebastian: 42188: Src/Modules/system.c: It is necessary to
+	close the lock descriptor in some failure cases.
+
 2018-01-04  Oliver Kiddle  <okiddle@yahoo.co.uk>
 
 	* dana: 42214: Completion/BSD/Type/_file_flags,
diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index 3eecd7e95..9fd4d2583 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -649,22 +649,30 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
     if (timeout > 0) {
 	time_t end = time(NULL) + (time_t)timeout;
 	while (fcntl(flock_fd, F_SETLK, &lck) < 0) {
-	    if (errflag)
+	    if (errflag) {
+                zclose(flock_fd);
 		return 1;
+            }
 	    if (errno != EINTR && errno != EACCES && errno != EAGAIN) {
+                zclose(flock_fd);
 		zwarnnam(nam, "failed to lock file %s: %e", args[0], errno);
 		return 1;
 	    }
-	    if (time(NULL) >= end)
+	    if (time(NULL) >= end) {
+                zclose(flock_fd);
 		return 2;
+            }
 	    sleep(1);
 	}
     } else {
 	while (fcntl(flock_fd, timeout == 0 ? F_SETLK : F_SETLKW, &lck) < 0) {
-	    if (errflag)
+	    if (errflag) {
+                zclose(flock_fd);
 		return 1;
+            }
 	    if (errno == EINTR)
 		continue;
+            zclose(flock_fd);
 	    zwarnnam(nam, "failed to lock file %s: %e", args[0], errno);
 	    return 1;
 	}