From 854c5543af75df216f1f7e14013ec02302240e88 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 28 Feb 2024 12:25:58 +0100 Subject: [PATCH] CID 437903 fix The strdup-ed pointer was actually not leaked but assigned to s->dir. There was, anyways, just one poblem, when the dir started with ':', so. `strtok(cfg_copy, ":")` would skip leading ':' returning cfg_copy+1. That would then be passed to free in export_destroy(), which would most likely crash on invalid pointer. --- src/export.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/export.c b/src/export.c index 6b10ea8e9..033e26790 100644 --- a/src/export.c +++ b/src/export.c @@ -139,10 +139,10 @@ struct exporter *export_init(struct module *parent, const char *cfg, bool should export_destroy(s); return NULL; } - char *cfg_copy = strdup(cfg); + s->dir = strdup(cfg); char *save_ptr = NULL; - s->dir = strtok_r(cfg_copy, ":", &save_ptr); - if (s->dir == NULL) { + char *item = strtok_r(s->dir, ":", &save_ptr); // skip the dir + if (item == NULL) { HANDLE_ERROR } if (!parse_options(s, save_ptr, &should_export)) {