Skip to content

Commit 6e76832

Browse files
kknjhchenhengqi
authored andcommitted
libbpf-tools: Fix the issue of unreleased resources
Fix the issue of unreleased resources Signed-off-by: Feng Yang <[email protected]>
1 parent 018ea04 commit 6e76832

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

libbpf-tools/uprobe_helpers.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ int get_pid_lib_path(pid_t pid, const char *lib, char *path, size_t path_sz)
5757
char proc_pid_maps[32];
5858
char line_buf[1024];
5959
char path_buf[1024];
60+
int err = -1;
6061

6162
if (snprintf(proc_pid_maps, sizeof(proc_pid_maps), "/proc/%d/maps", pid)
6263
>= sizeof(proc_pid_maps)) {
@@ -86,16 +87,17 @@ int get_pid_lib_path(pid_t pid, const char *lib, char *path, size_t path_sz)
8687
continue;
8788
if (strnlen(path_buf, 1024) >= path_sz) {
8889
warn("path size too small\n");
89-
return -1;
90+
goto cleanup;
9091
}
9192
strcpy(path, path_buf);
92-
fclose(maps);
93-
return 0;
93+
err = 0;
94+
goto cleanup;
9495
}
9596

9697
warn("Cannot find library %s\n", lib);
98+
cleanup:
9799
fclose(maps);
98-
return -1;
100+
return err;
99101
}
100102

101103
/*

0 commit comments

Comments
 (0)