From 2ffc30168e23ea037177ca929398b9a91c9134ea Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 28 Jul 2016 14:04:23 +1000 Subject: ctdb-mutex: Fix CID 1359217 Resource leak (RESOURCE_LEAK) BUG: https://bugzilla.samba.org/show_bug.cgi?id=12110 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs Autobuild-User(master): Amitay Isaacs Autobuild-Date(master): Wed Aug 3 09:13:55 CEST 2016 on sn-devel-144 (cherry picked from commit 24e28c0aa52399f03acf830a1ad72af0139b0606) --- ctdb/server/ctdb_mutex_fcntl_helper.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'ctdb/server') diff --git a/ctdb/server/ctdb_mutex_fcntl_helper.c b/ctdb/server/ctdb_mutex_fcntl_helper.c index 93c7f6236dd..06c2205d496 100644 --- a/ctdb/server/ctdb_mutex_fcntl_helper.c +++ b/ctdb/server/ctdb_mutex_fcntl_helper.c @@ -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; } -- cgit v1.2.1