Message ID | 20221205084741.3426393-1-gnaaman@drivenets.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 0faec4d050b607f7544b6cf9a4c2d57e191f981f |
Delegated to: | Stephen Hemminger |
Headers | show |
Series | [iproute2] libnetlink: Fix memory leak in __rtnl_talk_iov() | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
Hello: This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <stephen@networkplumber.org>: On Mon, 5 Dec 2022 10:47:41 +0200 you wrote: > From: Lahav Schlesinger <lschlesinger@drivenets.com> > > If `__rtnl_talk_iov` fails then callers are not expected to free `answer`. > > Currently if `NLMSG_ERROR` was received with an error then the netlink > buffer was stored in `answer`, while still returning an error > > [...] Here is the summary with links: - [iproute2] libnetlink: Fix memory leak in __rtnl_talk_iov() https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=0faec4d050b6 You are awesome, thank you!
diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 9af06232..001efc1d 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -1092,14 +1092,19 @@ next: rtnl_talk_error(h, err, errfn); } - if (answer) - *answer = (struct nlmsghdr *)buf; - else + if (i < iovlen) { free(buf); - - if (i < iovlen) goto next; - return error ? -i : 0; + } + + if (error) { + free(buf); + return -i; + } + + if (answer) + *answer = (struct nlmsghdr *)buf; + return 0; } if (answer) {