aboutsummaryrefslogtreecommitdiff
path: root/src/lib
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
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')
-rw-r--r--src/lib/core/conda.c3
-rw-r--r--src/lib/delivery/delivery.c20
-rw-r--r--src/lib/delivery/delivery_build.c2
-rw-r--r--src/lib/delivery/delivery_test.c38
-rw-r--r--src/lib/delivery/include/delivery.h6
5 files changed, 44 insertions, 25 deletions
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);
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_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;
}
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) {
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
@@ -522,6 +522,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
*/