Skip to content

Commit 1300655

Browse files
committed
FIX: graceful cleanup
1 parent b0477fe commit 1300655

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

bpftools/profile_nginx_lua/profile.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ int main(int argc, char **argv)
768768
};
769769
struct syms_cache *syms_cache = NULL;
770770
struct ksyms *ksyms = NULL;
771+
struct perf_buffer *pb = NULL;
771772
struct bpf_link *cpu_links[MAX_CPU_NR] = {};
772773
struct bpf_link *uprobe_links[UPROBE_SIZE] = {};
773774
struct profile_bpf *obj;
@@ -860,8 +861,8 @@ int main(int argc, char **argv)
860861
lua_bt_map = init_lua_stack_map();
861862
if (!lua_bt_map)
862863
goto cleanup;
863-
struct perf_buffer *pb = perf_buffer__new(bpf_map__fd(obj->maps.lua_event_output), PERF_BUFFER_PAGES,
864-
handle_lua_stack_event, handle_lua_stack_lost_events, NULL, NULL);
864+
pb = perf_buffer__new(bpf_map__fd(obj->maps.lua_event_output), PERF_BUFFER_PAGES,
865+
handle_lua_stack_event, handle_lua_stack_lost_events, NULL, NULL);
865866
if (!pb)
866867
{
867868
err = -errno;
@@ -931,8 +932,11 @@ int main(int argc, char **argv)
931932
for (i = 0; i < UPROBE_SIZE; i++)
932933
bpf_link__destroy(uprobe_links[i]);
933934
profile_bpf__destroy(obj);
934-
perf_buffer__free(pb);
935-
syms_cache__free(syms_cache);
936-
ksyms__free(ksyms);
935+
if (pb)
936+
perf_buffer__free(pb);
937+
if (syms_cache)
938+
syms_cache__free(syms_cache);
939+
if (ksyms)
940+
ksyms__free(ksyms);
937941
return err != 0;
938942
}

0 commit comments

Comments
 (0)