Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples/bpf: Fix a resource leak

The opened file should be closed in show_sockopts(), otherwise resource
leak will occur that this problem was discovered by reading code

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20241010014126.2573-1-zhujun2@cmss.chinamobile.com

authored by

Zhu Jun and committed by
Andrii Nakryiko
f3ef5317 c6ca3198

+3 -1
+3 -1
samples/bpf/test_cgrp2_sock.c
··· 178 178 return 1; 179 179 } 180 180 181 - if (get_bind_to_device(sd, name, sizeof(name)) < 0) 181 + if (get_bind_to_device(sd, name, sizeof(name)) < 0) { 182 + close(sd); 182 183 return 1; 184 + } 183 185 184 186 mark = get_somark(sd); 185 187 prio = get_priority(sd);