From: Jérémie Galarneau Date: Fri, 31 Jan 2020 22:38:23 +0000 (-0500) Subject: Tests: fd-tracker: fix: leak of test paths X-Git-Tag: v2.12.0-rc1~14 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f6bef9660a264ebeb2a00e80bf48bec41fb47c1a;p=lttng-tools.git Tests: fd-tracker: fix: leak of test paths Leak of memory or pointers to system resources (CWE-404) Reported-by: Coverity Scan Signed-off-by: Jérémie Galarneau Change-Id: Id57254c990ee43dc6901c7778655830e0564e975 --- diff --git a/src/common/fd-tracker/fd-tracker.c b/src/common/fd-tracker/fd-tracker.c index 188abfb6d..033ae40f8 100644 --- a/src/common/fd-tracker/fd-tracker.c +++ b/src/common/fd-tracker/fd-tracker.c @@ -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. diff --git a/tests/unit/test_fd_tracker.c b/tests/unit/test_fd_tracker.c index 42941786e..cb192ff80 100644 --- a/tests/unit/test_fd_tracker.c +++ b/tests/unit/test_fd_tracker.c @@ -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);