ctdb-utils: CID 1273087 - Resource leak
authorMartin Schwenke <martin@meltin.net>
Wed, 3 Jul 2019 10:40:44 +0000 (20:40 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 17 Sep 2019 04:35:26 +0000 (04:35 +0000)
Ensure that p is not leaked.

This is a test program and the program exits anyway.  No need to
backport.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/utils/ping_pong/ping_pong.c

index 2b337faaf55416b325e53e094f3fe0016c89b11e..3d28f34982d523b78b3e6704037b39617e36e7f5 100644 (file)
@@ -153,8 +153,7 @@ static void ping_pong(int fd, int num_locks)
        ret = lock_range(fd, 0, 1, true);
        if (ret != 0) {
                printf("initial lock at 0 failed! - %s\n", strerror(errno));
-               free(val);
-               return;
+               goto done;
        }
 
        i = 0;
@@ -167,8 +166,7 @@ static void ping_pong(int fd, int num_locks)
                if (do_check) {
                        ret = check_lock(fd, i, 1);
                        if (ret != 0) {
-                               free(val);
-                               return;
+                               goto done;
                        }
                }
                if (do_reads) {
@@ -209,6 +207,12 @@ static void ping_pong(int fd, int num_locks)
                }
                loops++;
        }
+
+done:
+       if (use_mmap) {
+               munmap(p, num_locks+1);
+       }
+       free(val);
 }
 
 static void usage(void)