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>
This commit is contained in:
parent
adc1e33f7e
commit
e82baa17ca
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user