Skip to content

Commit

Permalink
selftests/bpf: Free strdup memory in xdp_hw_metadata
Browse files Browse the repository at this point in the history
The strdup() function returns a pointer to a new string which is a
duplicate of the string "ifname". Memory for the new string is obtained
with malloc(), and need to be freed with free().

This patch adds this missing "free(saved_hwtstamp_ifname)" in cleanup()
to avoid a potential memory leak in xdp_hw_metadata.c.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/af9bcccb96655e82de5ce2b4510b88c9c8ed5ed0.1715417367.git.tanggeliang@kylinos.cn
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Geliang Tang authored and Alexei Starovoitov committed May 13, 2024
1 parent 5ddafcc commit a3c1c95
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/testing/selftests/bpf/xdp_hw_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ static void cleanup(void)

if (bpf_obj)
xdp_hw_metadata__destroy(bpf_obj);

free((void *)saved_hwtstamp_ifname);
}

static void handle_signal(int sig)
Expand Down

0 comments on commit a3c1c95

Please sign in to comment.