]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
tree: Fix clearing application strings
authorTomas Bzatek <tbzatek@redhat.com>
Thu, 23 Nov 2023 17:52:20 +0000 (18:52 +0100)
committerDaniel Wagner <wagi@monom.org>
Mon, 27 Nov 2023 12:16:55 +0000 (13:16 +0100)
Freeing strings without clearing to NULL may potentially lead
to double-free later when freeing the tree structs.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
src/nvme/tree.c

index 5636aa1809ec6a3358e527110deba6e67288e389..3c8e75253c2eaae6718c28732406e4f5aa25f53e 100644 (file)
@@ -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);
 }