From e82baa17ca49b8dac03579fe71d28a7cdc95e955 Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 29 Mar 2022 09:11:01 +0100 Subject: 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 --- src/checkpath/checkpath.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') 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); -- cgit v1.2.3