aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2025-01-31 00:14:19 -0500
committerGitHub <noreply@github.com>2025-01-31 00:14:19 -0500
commit3ef26a80fc365ec9c857aaf40741fa6acf8987fa (patch)
treeb8dfd9d162e136b921366cbe1350acbd15866385
parentf64f82bc6a1aec53a924d21deb65a60da1020d0e (diff)
parent4de01eed23b68a7872fce17ec27b41b333bb3d10 (diff)
downloadstasis-3ef26a80fc365ec9c857aaf40741fa6acf8987fa.tar.gz
Merge pull request #83 from jhunkeler/bug-fix-leaks-indexer
Indexer: Fix garbage in file path
-rw-r--r--src/cli/stasis_indexer/helpers.c6
-rw-r--r--src/cli/stasis_indexer/junitxml_report.c8
-rw-r--r--src/cli/stasis_indexer/stasis_indexer_main.c6
3 files changed, 17 insertions, 3 deletions
diff --git a/src/cli/stasis_indexer/helpers.c b/src/cli/stasis_indexer/helpers.c
index 6d2fdd0..5ae01ca 100644
--- a/src/cli/stasis_indexer/helpers.c
+++ b/src/cli/stasis_indexer/helpers.c
@@ -35,6 +35,7 @@ int get_pandoc_version(size_t *result) {
char *version_str = shell_output("pandoc --version", &state);
if (state || !version_str) {
// an error occurred
+ guard_free(version_str);
return -1;
}
@@ -44,6 +45,7 @@ int get_pandoc_version(size_t *result) {
char *v_begin = &version_str[7];
if (!v_begin) {
SYSERROR("unexpected pandoc output: %s", version_str);
+ guard_free(version_str);
return -1;
}
char *v_end = strchr(version_str, '\n');
@@ -54,6 +56,7 @@ int get_pandoc_version(size_t *result) {
char **parts = split(v_begin, ".", 0);
if (!parts) {
SYSERROR("unable to split pandoc version string, '%s': %s", version_str, strerror(errno));
+ guard_free(version_str);
return -1;
}
@@ -71,11 +74,14 @@ int get_pandoc_version(size_t *result) {
// pack version element into result
*result = *result << 8 | tmp;
}
+ GENERIC_ARRAY_FREE(parts);
} else {
// invalid version string
+ guard_free(version_str);
return 1;
}
+ guard_free(version_str);
return 0;
}
diff --git a/src/cli/stasis_indexer/junitxml_report.c b/src/cli/stasis_indexer/junitxml_report.c
index d7d8f9a..fbb36af 100644
--- a/src/cli/stasis_indexer/junitxml_report.c
+++ b/src/cli/stasis_indexer/junitxml_report.c
@@ -28,7 +28,7 @@ static int write_report_output(struct Delivery *ctx, FILE *destfp, const char *x
}
char *bname_tmp = strdup(xmlfilename);
- char *bname = path_basename(bname_tmp);
+ char *bname = strdup(path_basename(bname_tmp));
if (endswith(bname, ".xml")) {
bname[strlen(bname) - 4] = 0;
}
@@ -51,6 +51,8 @@ static int write_report_output(struct Delivery *ctx, FILE *destfp, const char *x
snprintf(result_outfile, sizeof(result_outfile) - strlen(bname) - 3, "%s.md",
bname);
+ guard_free(bname);
+
FILE *resultfp = fopen(result_outfile, "w+");
if (!resultfp) {
SYSERROR("Unable to open %s for writing", result_outfile);
@@ -103,7 +105,7 @@ int indexer_junitxml_report(struct Delivery ctx[], const size_t nelem) {
fprintf(stderr, "Unable to open %s for writing\n", indexfile);
return -1;
}
- printf("index %s opened for writing", indexfile);
+ printf("Index %s opened for writing\n", indexfile);
for (size_t d = 0; d < nelem; d++) {
char pattern[PATH_MAX] = {0};
@@ -137,8 +139,10 @@ int indexer_junitxml_report(struct Delivery ctx[], const size_t nelem) {
popd();
} else {
fprintf(stderr, "Unable to enter delivery directory: %s\n", ctx->storage.delivery_dir);
+ guard_strlist_free(&file_listing);
return -1;
}
+ guard_strlist_free(&file_listing);
return 0;
}
diff --git a/src/cli/stasis_indexer/stasis_indexer_main.c b/src/cli/stasis_indexer/stasis_indexer_main.c
index ef39394..86f7834 100644
--- a/src/cli/stasis_indexer/stasis_indexer_main.c
+++ b/src/cli/stasis_indexer/stasis_indexer_main.c
@@ -204,7 +204,7 @@ int main(const int argc, char *argv[]) {
const int current_index = optind;
if (optind < argc) {
rootdirs_total = argc - current_index;
- rootdirs = calloc(rootdirs_total + 1, sizeof(**rootdirs));
+ rootdirs = calloc(rootdirs_total + 1, sizeof(*rootdirs));
int i = 0;
while (optind < argc) {
@@ -391,8 +391,12 @@ int main(const int argc, char *argv[]) {
guard_free(destdir);
GENERIC_ARRAY_FREE(rootdirs);
guard_strlist_free(&metafiles);
+ guard_free(m.micromamba_prefix);
delivery_free(&ctx);
+ guard_free(local);
globals_free();
+
msg(STASIS_MSG_L1, "Done!\n");
+
return 0;
}