ctdb-mutex: Fix CID 1359217 Resource leak (RESOURCE_LEAK)
authorMartin Schwenke <martin@meltin.net>
Thu, 28 Jul 2016 04:04:23 +0000 (14:04 +1000)
committerAmitay Isaacs <amitay@samba.org>
Wed, 3 Aug 2016 07:13:55 +0000 (09:13 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Wed Aug  3 09:13:55 CEST 2016 on sn-devel-144

ctdb/server/ctdb_mutex_fcntl_helper.c

index 93c7f6236dd578f8d559c915350167ee22c78046..06c2205d4969526365cc47885b1c14b9dcdb157f 100644 (file)
@@ -27,7 +27,7 @@
 
 static char *progname = NULL;
 
-static char fcntl_lock(const char *file)
+static char fcntl_lock(const char *file, int *outfd)
 {
        int fd;
        struct flock lock;
@@ -62,6 +62,8 @@ static char fcntl_lock(const char *file)
                return '3';
        }
 
+       *outfd = fd;
+
        return '0';
 }
 
@@ -70,6 +72,7 @@ int main(int argc, char *argv[])
        char result;
        int ppid;
        const char *file = NULL;
+       int fd = -1;
 
        progname = argv[0];
 
@@ -81,10 +84,14 @@ int main(int argc, char *argv[])
        ppid = getppid();
        file = argv[1];
 
-       result = fcntl_lock(file);
+       result = fcntl_lock(file, &fd);
        sys_write(STDOUT_FILENO, &result, 1);
 
        ctdb_wait_for_process_to_exit(ppid);
 
+       if (fd != -1) {
+               close(fd);
+       }
+
        return 0;
 }