s4:torture: Do not leak file descriptor in smb2 oplock test
authorAndreas Schneider <asn@samba.org>
Wed, 16 May 2018 09:46:22 +0000 (11:46 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 17 May 2018 02:03:21 +0000 (04:03 +0200)
Found by Coverity.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu May 17 04:03:21 CEST 2018 on sn-devel-144

source4/torture/smb2/oplock.c

index 6e53007bcfc14b42a62cc4f02e57cd8255de67c4..800a4cf299f28459b193db116599dbb2fb3cb5f2 100644 (file)
@@ -4873,17 +4873,20 @@ static int do_child_process(int pipefd, const char *name)
 
        ret = fcntl(fd, F_SETSIG, RT_SIGNAL_LEASE);
        if (ret == -1) {
+               close(fd);
                return 3;
        }
 
        ret = fcntl(fd, F_SETLEASE, F_WRLCK);
        if (ret == -1) {
+               close(fd);
                return 4;
        }
 
        /* Tell the parent we're ready. */
        ret = sys_write(pipefd, &c, 1);
        if (ret != 1) {
+               close(fd);
                return 5;
        }
 
@@ -4893,14 +4896,17 @@ static int do_child_process(int pipefd, const char *name)
        /* Wait for RT_SIGNAL_LEASE or SIGALRM. */
        ret = sigsuspend(&empty_set);
        if (ret != -1 || errno != EINTR) {
+               close(fd);
                return 6;
        }
 
        if (got_alarm == 1) {
+               close(fd);
                return 10;
        }
 
        if (got_break != 1) {
+               close(fd);
                return 7;
        }
 
@@ -4913,6 +4919,7 @@ static int do_child_process(int pipefd, const char *name)
        /* Remove our lease. */
        ret = fcntl(fd, F_SETLEASE, F_UNLCK);
        if (ret == -1) {
+               close(fd);
                return 8;
        }