aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2023-01-06 06:39:30 +0000
committerSam James <sam@gentoo.org>2023-01-10 05:21:39 +0000
commit776afeae92d2afd3340cd753abc58ccd8daba48f (patch)
tree353a4e1303edc72a328ff8154ce67593ed8f74be
parentinstall-xattr: avoid accessing empty storage (diff)
downloadelfix-776afeae92d2afd3340cd753abc58ccd8daba48f.tar.gz
elfix-776afeae92d2afd3340cd753abc58ccd8daba48f.tar.bz2
elfix-776afeae92d2afd3340cd753abc58ccd8daba48f.zip
install-xattr: fix small memory leak
There's another with strdup/malloc but it gets a bit messier to fix so let's leave that for now (this is mostly about correctness anyway, as the runtime of install-xattr is very small): ``` Direct leak of 4097 byte(s) in 1 object(s) allocated from: #0 0x7f4a2c22e257 in __interceptor_malloc /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/asan/asan_malloc_linux.cpp:69 #1 0x7f4a2c1d2b40 in __interceptor_realpath /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3904 #2 0x55da3adf5629 in realpath /usr/include/bits/stdlib.h:42 #3 0x55da3adf5629 in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:252 ``` Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--misc/install-xattr/install-xattr.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/misc/install-xattr/install-xattr.c b/misc/install-xattr/install-xattr.c
index db6dabd..23b6af3 100644
--- a/misc/install-xattr/install-xattr.c
+++ b/misc/install-xattr/install-xattr.c
@@ -248,7 +248,6 @@ main(int argc, char* argv[])
char *target = NULL; /* the target file or directory */
char *path; /* path to the target file */
- char *mypath = realpath("/proc/self/exe", NULL); /* path to argv[0] */
char *install; /* path to the system install */
struct stat s; /* test if a file is a regular file or a directory */
@@ -353,7 +352,9 @@ main(int argc, char* argv[])
case -1:
err(1, "fork() failed");
- case 0:
+ case 0: {
+ char *mypath = realpath("/proc/self/exe", NULL); /* path to argv[0] */
+
/* find system install avoiding mypath and portage_helper_path! */
if (portage_helper_path)
portage_helper_canpath = realpath(portage_helper_path, NULL);
@@ -363,6 +364,7 @@ main(int argc, char* argv[])
argv[0] = install; /* so coreutils' lib/program.c behaves */
execv(install, argv); /* The kernel will free(install). */
err(1, "execv() failed");
+ }
default:
wait(&status);