Skip to content

Commit 0da1f66

Browse files
tbzatekigaw
authored andcommitted
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 <[email protected]>
1 parent 4fe9e40 commit 0da1f66

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/nvme/tree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,10 @@ const char *nvme_root_get_application(nvme_root_t r)
261261

262262
void nvme_root_set_application(nvme_root_t r, const char *a)
263263
{
264-
if (r->application)
264+
if (r->application) {
265265
free(r->application);
266+
r->application = NULL;
267+
}
266268
if (a)
267269
r->application = strdup(a);
268270
}
@@ -404,8 +406,10 @@ const char *nvme_subsystem_get_application(nvme_subsystem_t s)
404406

405407
void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a)
406408
{
407-
if (s->application)
409+
if (s->application) {
408410
free(s->application);
411+
s->application = NULL;
412+
}
409413
if (a)
410414
s->application = strdup(a);
411415
}

0 commit comments

Comments
 (0)