From: Zongmin Zhou <zhouzong...@kylinos.cn> The buffer be used without free,fix it to avoid memory leak.
Signed-off-by: Zongmin Zhou <zhouzong...@kylinos.cn> --- Changes in v2: - add the label to use instead of directly to use on each case. --- tools/testing/selftests/net/cmsg_sender.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c index a825e628aee7..71984e0a44e2 100644 --- a/tools/testing/selftests/net/cmsg_sender.c +++ b/tools/testing/selftests/net/cmsg_sender.c @@ -491,7 +491,8 @@ int main(int argc, char *argv[]) if (err) { fprintf(stderr, "Can't resolve address [%s]:%s\n", opt.host, opt.service); - return ERN_SOCK_CREATE; + err = ERN_SOCK_CREATE; + goto err_free_buff; } if (ai->ai_family == AF_INET6 && opt.sock.proto == IPPROTO_ICMP) @@ -501,7 +502,8 @@ int main(int argc, char *argv[]) if (fd < 0) { fprintf(stderr, "Can't open socket: %s\n", strerror(errno)); freeaddrinfo(ai); - return ERN_RESOLVE; + err = ERN_RESOLVE; + goto err_free_buff; } if (opt.sock.proto == IPPROTO_ICMP) { @@ -575,5 +577,7 @@ int main(int argc, char *argv[]) err_out: close(fd); freeaddrinfo(ai); +err_free_buff: + free(buf); return err; } -- 2.34.1