Skip to content

Commit

Permalink
tree: Fix clearing application strings
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tbzatek authored and igaw committed Nov 27, 2023
1 parent 4fe9e40 commit 0da1f66
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 0da1f66

Please sign in to comment.