Tests: fd-tracker: fix: leak of test paths
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 31 Jan 2020 22:38:23 +0000 (17:38 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 31 Jan 2020 22:38:23 +0000 (17:38 -0500)
Leak of memory or pointers to system resources (CWE-404)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Id57254c990ee43dc6901c7778655830e0564e975

src/common/fd-tracker/fd-tracker.c
tests/unit/test_fd_tracker.c

index 188abfb6d2792f4f3f2eb9d899e6fb62d784f522..033ae40f8516f6389e1d0b46db1ad01b8bc6ea20 100644 (file)
@@ -457,6 +457,9 @@ int fd_tracker_destroy(struct fd_tracker *tracker)
 {
        int ret = 0;
 
+       if (!tracker) {
+               goto end;
+       }
        /*
         * Refuse to destroy the tracker as fs_handles may still old
         * weak references to the tracker.
index 42941786e38ed569121d0ab2e06ab84c29b40695..cb192ff80019d95b1932502c501f4882e9fbb533 100644 (file)
@@ -187,7 +187,7 @@ void test_unsuspendable_basic(void)
        ok(tracker, "Created an fd tracker with a limit of %d simulateously opened file descriptors",
                        TRACKER_FD_LIMIT);
        if (!tracker) {
-               return;
+               goto end;
        }
 
        track_std_fds(tracker);
@@ -196,6 +196,7 @@ void test_unsuspendable_basic(void)
        fd_tracker_destroy(tracker);
        ret = rmdir(test_directory);
        ok(ret == 0, "Test directory is empty");
+end:
        free(test_directory);
        free(unlinked_files_directory);
 }
@@ -379,7 +380,7 @@ void test_unsuspendable_close_untracked(void)
 
         tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
        if (!tracker) {
-               return;
+               goto end;;
        }
 
        ret = pipe(unknown_fds);
@@ -402,6 +403,7 @@ void test_unsuspendable_close_untracked(void)
        fd_tracker_destroy(tracker);
        ret = rmdir(test_directory);
        ok(ret == 0, "Test directory is empty");
+end:
        free(test_directory);
        free(unlinked_files_directory);
 }
@@ -506,7 +508,7 @@ void test_suspendable_limit(void)
 
         tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
        if (!tracker) {
-               return;
+               goto end;
        }
 
        dir_handle = lttng_directory_handle_create(test_directory);
@@ -527,6 +529,7 @@ void test_suspendable_limit(void)
        ok(ret == 0, "Test directory is empty");
        fd_tracker_destroy(tracker);
        lttng_directory_handle_put(dir_handle);
+end:
        free(test_directory);
        free(unlinked_files_directory);
 }
@@ -550,7 +553,7 @@ void test_mixed_limit(void)
 
        tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
        if (!tracker) {
-               return;
+               goto end;
        }
 
        dir_handle = lttng_directory_handle_create(test_directory);
@@ -586,6 +589,7 @@ void test_mixed_limit(void)
        ok(ret == 0, "Test directory is empty");
        fd_tracker_destroy(tracker);
        lttng_directory_handle_put(dir_handle);
+end:
        free(test_directory);
        free(unlinked_files_directory);
 }
@@ -622,7 +626,7 @@ void test_suspendable_restore(void)
 
         tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
        if (!tracker) {
-               return;
+               goto end;
        }
 
        dir_handle = lttng_directory_handle_create(test_directory);
@@ -729,6 +733,7 @@ skip_write:
        ok(ret == 0, "Test directory is empty");
        fd_tracker_destroy(tracker);
        lttng_directory_handle_put(dir_handle);
+end:
        free(test_directory);
        free(unlinked_files_directory);
 }
@@ -758,7 +763,7 @@ void test_unlink(void)
 
        tracker = fd_tracker_create(unlinked_files_directory, 1);
        if (!tracker) {
-               return;
+               goto end;
        }
 
        dir_handle = lttng_directory_handle_create(test_directory);
@@ -770,7 +775,7 @@ void test_unlink(void)
        ok(!ret, "Successfully opened %i handles to %s/%s", handles_to_open,
                        test_directory, file_name);
        if (ret) {
-               return;
+               goto end;
        }
 
        /*
@@ -859,6 +864,7 @@ void test_unlink(void)
 
        ret = rmdir(test_directory);
        ok(ret == 0, "Test directory is empty");
+end:
        fd_tracker_destroy(tracker);
        free(test_directory);
        free(unlinked_files_directory);
This page took 0.039345 seconds and 5 git commands to generate.