]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
libbpf: Fix memleak in libbpf_netlink_recv()
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 17 Feb 2022 07:39:58 +0000 (23:39 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 17 Feb 2022 15:09:07 +0000 (16:09 +0100)
Ensure that libbpf_netlink_recv() frees dynamically allocated buffer in
all code paths.

Fixes: 9c3de619e13e ("libbpf: Use dynamically allocated buffer when receiving netlink messages")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20220217073958.276959-1-andrii@kernel.org
tools/lib/bpf/netlink.c

index a598061f6fea52b257f2f7e3bed3cee605728256..cbc8967d540210958a15a8ed998647da6bdbf26a 100644 (file)
@@ -176,7 +176,8 @@ start:
                                libbpf_nla_dump_errormsg(nh);
                                goto done;
                        case NLMSG_DONE:
-                               return 0;
+                               ret = 0;
+                               goto done;
                        default:
                                break;
                        }
@@ -188,9 +189,10 @@ start:
                                case NL_NEXT:
                                        goto start;
                                case NL_DONE:
-                                       return 0;
+                                       ret = 0;
+                                       goto done;
                                default:
-                                       return ret;
+                                       goto done;
                                }
                        }
                }