From fd2e8d9d2bc3dcce3707823c0ec0643f066c0b3f Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Apr 2026 19:06:04 -0400 Subject: Fix incorrect size used by realloc --- src/lib/delivery/delivery_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c index 3ba9d56..ce6d73d 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; -- cgit From d25ffbedb80fc4e02945c518dcae91d3a5ef6db6 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Apr 2026 19:54:35 -0400 Subject: Expose tests_free() --- src/lib/delivery/include/delivery.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/delivery/include/delivery.h b/src/lib/delivery/include/delivery.h index b5799ac..68f4b14 100644 --- a/src/lib/delivery/include/delivery.h +++ b/src/lib/delivery/include/delivery.h @@ -521,6 +521,12 @@ int tests_add(struct Tests *tests, struct Test *x); */ void test_free(struct Test **x); +/** + * Free a `Tests` structure + * @param x pointer to `Tests` + */ +void tests_free(struct Tests **x); + /** * Initialize a `Test` structure * @return an initialized `Test` structure -- cgit From 0268551a0c9b1e6cba422efa88f36cb8e663bd82 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Apr 2026 19:55:21 -0400 Subject: Check memory allocations on init --- src/lib/delivery/delivery_test.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c index ce6d73d..b879689 100644 --- a/src/lib/delivery/delivery_test.c +++ b/src/lib/delivery/delivery_test.c @@ -37,7 +37,14 @@ 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; } -- cgit From 38010fc9eea2d914de8f3058979baace3f1d1e80 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Apr 2026 19:58:52 -0400 Subject: Move test free code from delivery.c:delivery_free() to delivery_test.c:test_free() --- src/lib/delivery/delivery.c | 20 +------------------- src/lib/delivery/delivery_test.c | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/lib/delivery/delivery.c b/src/lib/delivery/delivery.c index 11dd7b0..be6e8ff 100644 --- a/src/lib/delivery/delivery.c +++ b/src/lib/delivery/delivery.c @@ -230,25 +230,7 @@ void delivery_free(struct Delivery *ctx) { guard_strlist_free(&ctx->conda.pip_packages_purge); guard_strlist_free(&ctx->conda.wheels_packages); - for (size_t i = 0; ctx->tests && i < ctx->tests->num_used; i++) { - guard_free(ctx->tests->test[i]->name); - guard_free(ctx->tests->test[i]->version); - guard_free(ctx->tests->test[i]->repository); - guard_free(ctx->tests->test[i]->repository_info_ref); - guard_free(ctx->tests->test[i]->repository_info_tag); - guard_strlist_free(&ctx->tests->test[i]->repository_remove_tags); - guard_free(ctx->tests->test[i]->script); - guard_free(ctx->tests->test[i]->script_setup); - guard_free(ctx->tests->test[i]->build_recipe); - // test-specific runtime variables - guard_runtime_free(ctx->tests->test[i]->runtime->environ); - guard_free(ctx->tests->test[i]->runtime); - guard_free(ctx->tests->test[i]); - } - if (ctx->tests) { - guard_free(ctx->tests->test); - guard_free(ctx->tests); - } + tests_free(&ctx->tests); guard_free(ctx->rules.release_fmt); guard_free(ctx->rules.build_name_fmt); diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c index b879689..ca40b00 100644 --- a/src/lib/delivery/delivery_test.c +++ b/src/lib/delivery/delivery_test.c @@ -51,14 +51,31 @@ struct Test *test_init() { 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; + 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) { -- cgit From 00314ad424035c5ed1ebdaf62cf387b8eeadeb55 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Apr 2026 19:59:08 -0400 Subject: Add test_tests.c --- tests/test_tests.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/test_tests.c diff --git a/tests/test_tests.c b/tests/test_tests.c new file mode 100644 index 0000000..0f6d7ca --- /dev/null +++ b/tests/test_tests.c @@ -0,0 +1,52 @@ +#include "delivery.h" +#include "testing.h" + +static struct Test *mock_test(const int ident) { + struct Test *test = test_init(); + if (asprintf(&test->name, "test_%d", ident) < 0) { + return NULL; + } + return test; +} + +void test_tests() { + const int initial = TEST_NUM_ALLOC_INITIAL; + const int balloon = initial * 10; + struct Tests *tests = tests_init(initial); + STASIS_ASSERT_FATAL(tests != NULL, "tests structure allocation failed"); + STASIS_ASSERT(tests->num_alloc == (size_t) initial, "incorrect number of records initialized"); + STASIS_ASSERT(tests->num_used == 0, "incorrect number of records used"); + + for (int i = 0; i < balloon; i++) { + struct Test *test = mock_test(i); + if (!test) { + SYSERROR("unable to allocate memory for test %d", i); + return; + } + tests_add(tests, test); + } + + size_t errors = 0; + for (int i = 0; i < initial * 10; i++) { + struct Test *test = tests->test[i]; + if (!test) { + errors++; + continue; + } + if (!test->name) { + errors++; + } + } + STASIS_ASSERT(errors == 0, "no errors should be detected in test->name member"); + + tests_free(&tests); +} + +int main(int argc, char *argv[]) { + STASIS_TEST_BEGIN_MAIN(); + STASIS_TEST_FUNC *tests[] = { + test_tests, + }; + STASIS_TEST_RUN(tests); + STASIS_TEST_END_MAIN(); +} \ No newline at end of file -- cgit From b97fe3f12080e2427c40f089af0c60217951291b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Apr 2026 20:01:40 -0400 Subject: ASAN: Darwin arm64 doesn't support "leak" --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd214ca..71e310b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ find_package(LibXml2) find_package(CURL) option(ASAN "Address Analyzer" OFF) -set(ASAN_OPTIONS "-fsanitize=address,leak,null,undefined") +set(ASAN_OPTIONS "-fsanitize=address,null,undefined") if (ASAN) add_compile_options(${ASAN_OPTIONS} -fno-omit-frame-pointer -g -O0) add_link_options(${ASAN_OPTIONS}) -- cgit From f9dcabc7cc5b098e7e6b7e0951dcd7467fdcece0 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Apr 2026 20:24:19 -0400 Subject: Fix invalid printf formatter --- src/lib/delivery/delivery_build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/delivery/delivery_build.c b/src/lib/delivery/delivery_build.c index 0013e96..1454d9a 100644 --- a/src/lib/delivery/delivery_build.c +++ b/src/lib/delivery/delivery_build.c @@ -367,7 +367,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { const int use_builder_manylinux = strcmp(globals.wheel_builder, "manylinux") == 0 && on_linux && docker_usable; if (!use_builder_build && !use_builder_cibuildwheel && !use_builder_manylinux) { - msg(STASIS_MSG_WARN, "Cannot build wheel for platform using: %\n", globals.wheel_builder); + msg(STASIS_MSG_WARN, "Cannot build wheel for platform using: %s\n", globals.wheel_builder); msg(STASIS_MSG_WARN, "Falling back to native toolchain.\n", globals.wheel_builder); use_builder_build = 1; } -- cgit From 33dc91ee4baa88aa678af0cb23cdd417c5a1144b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 9 Apr 2026 02:03:36 -0400 Subject: Clear errno on touch --- src/lib/core/conda.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index de6130f..c9be7a3 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -58,6 +58,9 @@ int micromamba(const struct MicromambaInfo *info, char *command, ...) { char rcpath[PATH_MAX]; sprintf(rcpath, "%s/.condarc", info->conda_prefix); touch(rcpath); + if (errno == ENOENT) { + errno = 0; + } setenv("CONDARC", rcpath, 1); setenv("MAMBA_ROOT_PREFIX", info->conda_prefix, 1); -- cgit From 3a00d248ca2a3ab9de44fc60cc6dd042ff512804 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 9 Apr 2026 02:04:02 -0400 Subject: Return immediately if tests struct is NULL --- src/lib/delivery/delivery_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c index ca40b00..96dbb10 100644 --- a/src/lib/delivery/delivery_test.c +++ b/src/lib/delivery/delivery_test.c @@ -71,6 +71,10 @@ void test_free(struct Test **x) { void tests_free(struct Tests **x) { struct Tests *tests = *x; + if (!tests) { + return; + } + for (size_t i = 0; i < tests->num_alloc; i++) { test_free(&tests->test[i]); } -- cgit From e800cc620976bf6ea8198ac66811f4596b6a3af1 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 9 Apr 2026 02:04:22 -0400 Subject: python3, not python --- tests/test_conda.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_conda.c b/tests/test_conda.c index 4d437e4..1d05e7e 100644 --- a/tests/test_conda.c +++ b/tests/test_conda.c @@ -20,7 +20,7 @@ void test_micromamba() { struct testcase tc[] = { {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "info", .result = 0}, {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "env list", .result = 0}, - {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "run python -V", .result = 0}, + {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "run python3 -V", .result = 0}, {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "no_such_option", .result = 109}, }; -- cgit