aboutsummaryrefslogtreecommitdiff
path: root/src/lib/delivery/delivery_test.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2026-04-09 06:58:14 -0400
committerGitHub <noreply@github.com>2026-04-09 06:58:14 -0400
commit1455ef340b1986ddd7e1c519f534ad051308a1ef (patch)
tree04255d8aa35cd689837614aa5c74bc8629037827 /src/lib/delivery/delivery_test.c
parent269e2c5eb511ef74fe293c428202ddeb38ada0db (diff)
parente800cc620976bf6ea8198ac66811f4596b6a3af1 (diff)
downloadstasis-1455ef340b1986ddd7e1c519f534ad051308a1ef.tar.gz
Merge pull request #131 from jhunkeler/realloc-sefault-tests_add
tests_add: Fix incorrect size used by realloc
Diffstat (limited to 'src/lib/delivery/delivery_test.c')
-rw-r--r--src/lib/delivery/delivery_test.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c
index 3ba9d56..96dbb10 100644
--- a/src/lib/delivery/delivery_test.c
+++ b/src/lib/delivery/delivery_test.c
@@ -21,10 +21,10 @@ int tests_add(struct Tests *tests, struct Test *x) {
#ifdef DEBUG
const size_t old_alloc = tests->num_alloc;
#endif
- struct Test **tmp = realloc(tests->test, tests->num_alloc++ * sizeof(*tests->test));
+ struct Test **tmp = realloc(tests->test, tests->num_alloc++ * sizeof(**tests->test));
SYSDEBUG("Increasing size of test array: %zu -> %zu", old_alloc, tests->num_alloc);
if (!tmp) {
- SYSDEBUG("Failed to allocate %zu bytes for test array", tests->num_alloc * sizeof(*tests->test));
+ SYSDEBUG("Failed to allocate %zu bytes for test array", tests->num_alloc * sizeof(**tests->test));
return -1;
}
tests->test = tmp;
@@ -37,21 +37,49 @@ int tests_add(struct Tests *tests, struct Test *x) {
struct Test *test_init() {
struct Test *result = calloc(1, sizeof(*result));
+ if (!result) {
+ return NULL;
+ }
+
result->runtime = calloc(1, sizeof(*result->runtime));
+ if (!result->runtime) {
+ return NULL;
+ }
return result;
}
void test_free(struct Test **x) {
struct Test *test = *x;
+ if (!test) {
+ return;
+ }
+ guard_free(test->name);
+ guard_free(test->version);
+ guard_free(test->repository);
+ guard_free(test->repository_info_ref);
+ guard_free(test->repository_info_tag);
+ guard_strlist_free(&test->repository_remove_tags);
+ guard_free(test->script);
+ guard_free(test->script_setup);
+ guard_free(test->build_recipe);
+ // test-specific runtime variables
+ guard_runtime_free(test->runtime->environ);
+ guard_free(test->runtime);
guard_free(test);
}
void tests_free(struct Tests **x) {
- for (size_t i = 0; i < (*x)->num_alloc; i++) {
- test_free(&(*x)->test[i]);
+ struct Tests *tests = *x;
+ if (!tests) {
+ return;
+ }
+
+ for (size_t i = 0; i < tests->num_alloc; i++) {
+ test_free(&tests->test[i]);
}
- guard_free((*x)->test);
+ guard_free(tests->test);
+ guard_free(tests);
}
void delivery_tests_run(struct Delivery *ctx) {