diff options
author | Ngie Cooper <yanegomi@gmail.com> | 2016-12-10 16:32:16 -0800 |
---|---|---|
committer | Ngie Cooper <yanegomi@gmail.com> | 2016-12-10 16:32:16 -0800 |
commit | 242f510fb0b478df8de89e76916b5e612288ff9a (patch) | |
tree | 29c37c123bbb3557e82f4383045b7b98a153c1f0 /tar/test | |
parent | f1b1881dfed9e8f4b2487aa74f6d151b1047539f (diff) | |
download | libarchive-242f510fb0b478df8de89e76916b5e612288ff9a.tar.gz |
Don't leak memory if returning from
assertion_file_contains_lines_any_order(..) early
Free memory consistently at the bottom of the function
Reported by: Coverity
CID: 1331678
Diffstat (limited to 'tar/test')
-rw-r--r-- | tar/test/main.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/tar/test/main.c b/tar/test/main.c index 9bb7964c..8d31706f 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -1060,7 +1060,7 @@ assertion_file_contains_lines_any_order(const char *file, int line, char **expected = NULL; char *p, **actual = NULL; char c; - int expected_failure = 0, actual_failure = 0; + int expected_failure = 0, actual_failure = 0, retval = 0; assertion_count(file, line); @@ -1081,8 +1081,7 @@ assertion_file_contains_lines_any_order(const char *file, int line, if (expected == NULL) { failure_start(pathname, line, "Can't allocate memory"); failure_finish(NULL); - free(expected); - return (0); + goto done; } for (i = 0; lines[i] != NULL; ++i) { expected[i] = strdup(lines[i]); @@ -1103,8 +1102,7 @@ assertion_file_contains_lines_any_order(const char *file, int line, if (actual == NULL) { failure_start(pathname, line, "Can't allocate memory"); failure_finish(NULL); - free(expected); - return (0); + goto done; } for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) { @@ -1141,27 +1139,27 @@ assertion_file_contains_lines_any_order(const char *file, int line, ++actual_failure; } if (expected_failure == 0 && actual_failure == 0) { - free(buff); - free(expected); - free(actual); - return (1); + retval = 1; + goto done; } failure_start(file, line, "File doesn't match: %s", pathname); for (i = 0; i < expected_count; ++i) { - if (expected[i] != NULL) { + if (expected[i] != NULL) logprintf(" Expected but not present: %s\n", expected[i]); - free(expected[i]); - } } for (j = 0; j < actual_count; ++j) { if (actual[j] != NULL) logprintf(" Present but not expected: %s\n", actual[j]); } failure_finish(NULL); +done: + free(actual); free(buff); + for (i = 0; i < expected_count; ++i) + free(expected[i]); free(expected); - free(actual); - return (0); + + return (retval); } /* Verify that a text file does not contains the specified strings */ |