diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-10-09 13:33:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 13:33:45 -0400 |
commit | 781f9873f20c45155e0dc3548bf47c74ab4a08fb (patch) | |
tree | 73d64f2b28a8742b2471b8549a81b1847f261edf | |
parent | 67dc983f124dd16c2e127fc5c9e4854e7bca9078 (diff) | |
parent | 8362f2c6150ec6e41a985764639d3d910e0da08c (diff) | |
download | stasis-781f9873f20c45155e0dc3548bf47c74ab4a08fb.tar.gz |
Merge pull request #59 from jhunkeler/leaks-and-squeaks
Leaks and squeaks
-rw-r--r-- | src/delivery_populate.c | 2 | ||||
-rw-r--r-- | src/delivery_test.c | 4 | ||||
-rw-r--r-- | src/ini.c | 16 | ||||
-rw-r--r-- | src/junitxml.c | 4 | ||||
-rw-r--r-- | src/stasis_indexer.c | 2 | ||||
-rw-r--r-- | src/str.c | 7 | ||||
-rw-r--r-- | tests/test_str.c | 2 |
7 files changed, 18 insertions, 19 deletions
diff --git a/src/delivery_populate.c b/src/delivery_populate.c index 02ce257..b37f677 100644 --- a/src/delivery_populate.c +++ b/src/delivery_populate.c @@ -277,7 +277,7 @@ int populate_mission_ini(struct Delivery **ctx, int render_mode) { (*ctx)->_stasis_ini_fp.mission = ini_open(missionfile); ini = (*ctx)->_stasis_ini_fp.mission; if (!ini) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to read misson configuration: %s, %s\n", missionfile, strerror(errno)); + msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to read mission configuration: %s, %s\n", missionfile, strerror(errno)); exit(1); } (*ctx)->_stasis_ini_fp.mission_path = strdup(missionfile); diff --git a/src/delivery_test.c b/src/delivery_test.c index 8ff08cc..e1d5efa 100644 --- a/src/delivery_test.c +++ b/src/delivery_test.c @@ -278,9 +278,7 @@ int delivery_fixup_test_results(struct Delivery *ctx) { char path[PATH_MAX]; memset(path, 0, sizeof(path)); - if (!strcmp(rec->d_name, ".") || !strcmp(rec->d_name, "..")) { - continue; - } else if (!endswith(rec->d_name, ".xml")) { + if (!strcmp(rec->d_name, ".") || !strcmp(rec->d_name, "..") || !endswith(rec->d_name, ".xml")) { continue; } @@ -319,10 +319,10 @@ int ini_data_append(struct INIFILE **ini, char *section_name, char *key, char *v } struct INIData **tmp = realloc(section->data, (section->data_count + 1) * sizeof(**section->data)); - if (tmp != section->data) { - section->data = tmp; - } else if (!tmp) { + if (tmp == NULL) { return 1; + } else { + section->data = tmp; } if (!ini_data_get((*ini), section_name, key)) { struct INIData **data = section->data; @@ -350,11 +350,11 @@ int ini_data_append(struct INIFILE **ini, char *section_name, char *key, char *v size_t value_len_new = value_len_old + value_len; char *value_tmp = NULL; value_tmp = realloc(data->value, value_len_new + 2); - if (value_tmp != data->value) { - data->value = value_tmp; - } else if (!value_tmp) { + if (!value_tmp) { SYSERROR("Unable to increase data->value size to %zu bytes", value_len_new + 2); return -1; + } else { + data->value = value_tmp; } strcat(data->value, value); } @@ -393,9 +393,9 @@ int ini_setval(struct INIFILE **ini, unsigned type, char *section_name, char *ke int ini_section_create(struct INIFILE **ini, char *key) { struct INISection **tmp = realloc((*ini)->section, ((*ini)->section_count + 1) * sizeof(**(*ini)->section)); - if (!tmp) { + if (tmp == NULL) { return 1; - } else if (tmp != (*ini)->section) { + } else { (*ini)->section = tmp; } diff --git a/src/junitxml.c b/src/junitxml.c index 9c7e5b4..c7d0834 100644 --- a/src/junitxml.c +++ b/src/junitxml.c @@ -37,9 +37,9 @@ void junitxml_testsuite_free(struct JUNIT_Testsuite **testsuite) { static int testsuite_append_testcase(struct JUNIT_Testsuite **testsuite, struct JUNIT_Testcase *testcase) { struct JUNIT_Testsuite *suite = (*testsuite); struct JUNIT_Testcase **tmp = realloc(suite->testcase, (suite->_tc_alloc + 1 ) * sizeof(*testcase)); - if (!tmp) { + if (tmp == NULL) { return -1; - } else if (tmp != suite->testcase) { + } else { suite->testcase = tmp; } suite->testcase[suite->_tc_inuse] = testcase; diff --git a/src/stasis_indexer.c b/src/stasis_indexer.c index 8ca7f44..05b9e39 100644 --- a/src/stasis_indexer.c +++ b/src/stasis_indexer.c @@ -405,7 +405,7 @@ static int micromamba_configure(const struct Delivery *ctx, struct MicromambaInf m->conda_prefix = globals.conda_install_prefix; m->micromamba_prefix = micromamba_prefix; - size_t pathvar_len = strlen(getenv("PATH")) + strlen(m->micromamba_prefix + strlen(m->conda_prefix)) + 3 + 4 + 1; + size_t pathvar_len = (strlen(getenv("PATH")) + strlen(m->micromamba_prefix) + strlen(m->conda_prefix)) + 3 + 4 + 1; // ^^^^^^^^^^^^^^^^^^ // 3 = separators // 4 = chars (/bin) @@ -175,7 +175,7 @@ char *join_ex(char *separator, ...) { } // Initialize array - argv = calloc(argc + 1, sizeof(char *)); + argv = calloc(argc + 1, sizeof(char **)); if (argv == NULL) { perror("join_ex calloc failed"); return NULL; @@ -196,8 +196,9 @@ char *join_ex(char *separator, ...) { char **tmp = realloc(argv, (argc + 1) * sizeof(char *)); if (tmp == NULL) { perror("join_ex realloc failed"); + guard_free(argv); return NULL; - } else if (tmp != argv) { + } else { argv = tmp; } size += strlen(current) + separator_len; @@ -583,7 +584,7 @@ char **strdup_array(char **array) { for (elems = 0; array[elems] != NULL; elems++); // Create new array - result = calloc(elems + 1, sizeof(result)); + result = calloc(elems + 1, sizeof(*result)); for (size_t i = 0; i < elems; i++) { result[i] = strdup(array[i]); } diff --git a/tests/test_str.c b/tests/test_str.c index f8aa1e9..4991c1c 100644 --- a/tests/test_str.c +++ b/tests/test_str.c @@ -244,7 +244,7 @@ void test_join_ex() { }; for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *result; - result = join_ex(tc[i].delim, "a", "b", "c", "d", "e", NULL); + result = join_ex((char *) tc[i].delim, "a", "b", "c", "d", "e", NULL); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "failed to join array"); guard_free(result); } |