Skip to content

Commit

Permalink
perf daemon: Use zfree() to reduce chances of use after free
Browse files Browse the repository at this point in the history
Do defensive programming by using zfree() to initialize freed pointers
to NULL, so that eventual use after free result in a NULL pointer deref
instead of more subtle behaviour.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Apr 12, 2023
1 parent 79b40a1 commit 789eae7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tools/perf/builtin-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static int session_config(struct daemon *daemon, const char *var, const char *va

if (!same) {
if (session->run) {
free(session->run);
zfree(&session->run);
pr_debug("reconfig: session %s is changed\n", name);
}

Expand Down Expand Up @@ -924,9 +924,9 @@ static void daemon__signal(struct daemon *daemon, int sig)

static void daemon_session__delete(struct daemon_session *session)
{
free(session->base);
free(session->name);
free(session->run);
zfree(&session->base);
zfree(&session->name);
zfree(&session->run);
free(session);
}

Expand Down Expand Up @@ -975,9 +975,9 @@ static void daemon__exit(struct daemon *daemon)
list_for_each_entry_safe(session, h, &daemon->sessions, list)
daemon_session__remove(session);

free(daemon->config_real);
free(daemon->config_base);
free(daemon->base);
zfree(&daemon->config_real);
zfree(&daemon->config_base);
zfree(&daemon->base);
}

static int daemon__reconfig(struct daemon *daemon)
Expand Down

0 comments on commit 789eae7

Please sign in to comment.