From ba65ce3e309e4f7a58ea67e14b93050cdc613a07 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Thu, 23 Nov 2023 18:52:20 +0100 Subject: [PATCH] tree: Fix clearing application strings Freeing strings without clearing to NULL may potentially lead to double-free later when freeing the tree structs. Signed-off-by: Tomas Bzatek --- src/nvme/tree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 5636aa18..3c8e7525 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -261,8 +261,10 @@ const char *nvme_root_get_application(nvme_root_t r) void nvme_root_set_application(nvme_root_t r, const char *a) { - if (r->application) + if (r->application) { free(r->application); + r->application = NULL; + } if (a) r->application = strdup(a); } @@ -404,8 +406,10 @@ const char *nvme_subsystem_get_application(nvme_subsystem_t s) void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a) { - if (s->application) + if (s->application) { free(s->application); + s->application = NULL; + } if (a) s->application = strdup(a); }