aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2022-03-29 09:11:01 +0100
committerWilliam Hubbs <w.d.hubbs@gmail.com>2022-05-08 14:56:26 -0500
commite82baa17ca49b8dac03579fe71d28a7cdc95e955 (patch)
tree822ac4dd39ca655dd03e309182108223eac3c243 /src
parentadc1e33f7e673d90b2ce169a3da337c6c22b6518 (diff)
checkpath: fix memory leak
``` ================================================================= ==22862==ERROR: LeakSanitizer: detected memory leaks Direct leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x7f1fd5b12cb7 in __interceptor_malloc /usr/src/debug/sys-devel/gcc-11.2.1_p20220312/gcc-11-20220312/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x55556abecea7 in xmalloc ../src/includes/helpers.h:64 #2 0x55556abecea7 in xasprintf ../src/includes/helpers.h:149 #3 0x55556abeb6fb in do_check ../src/rc/checkpath.c:206 #4 0x55556abeb6fb in main ../src/rc/checkpath.c:443 #5 0x7f1fd58576cf in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 SUMMARY: AddressSanitizer: 4096 byte(s) leaked in 1 allocation(s). ``` Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/checkpath/checkpath.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/checkpath/checkpath.c b/src/checkpath/checkpath.c
index 42864276..a98703a9 100644
--- a/src/checkpath/checkpath.c
+++ b/src/checkpath/checkpath.c
@@ -215,6 +215,7 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
fd = openat(dirfd, name, flags, mode);
umask(u);
if (fd == -1) {
+ free(name);
eerror("%s: open: %s", applet, strerror(errno));
return -1;
}
@@ -230,12 +231,14 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
r = mkdirat(dirfd, name, mode);
umask(u);
if (r == -1 && errno != EEXIST) {
+ free(name);
eerror("%s: mkdirat: %s", applet,
strerror (errno));
return -1;
}
readfd = openat(dirfd, name, readflags);
if (readfd == -1) {
+ free(name);
eerror("%s: unable to open directory: %s", applet,
strerror(errno));
return -1;
@@ -248,18 +251,23 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
r = mkfifo(path, mode);
umask(u);
if (r == -1 && errno != EEXIST) {
+ free(name);
eerror("%s: mkfifo: %s", applet,
strerror (errno));
return -1;
}
readfd = openat(dirfd, name, readflags);
if (readfd == -1) {
+ free(name);
eerror("%s: unable to open fifo: %s", applet,
strerror(errno));
return -1;
}
}
}
+
+ free(name);
+
if (fstat(readfd, &st) != -1) {
if (type != inode_dir && S_ISDIR(st.st_mode)) {
eerror("%s: is a directory", path);