Skip to content

Commit e82baa1

Browse files
thesamesamwilliamh
authored andcommitted
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>
1 parent adc1e33 commit e82baa1

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/checkpath/checkpath.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
215215
fd = openat(dirfd, name, flags, mode);
216216
umask(u);
217217
if (fd == -1) {
218+
free(name);
218219
eerror("%s: open: %s", applet, strerror(errno));
219220
return -1;
220221
}
@@ -230,12 +231,14 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
230231
r = mkdirat(dirfd, name, mode);
231232
umask(u);
232233
if (r == -1 && errno != EEXIST) {
234+
free(name);
233235
eerror("%s: mkdirat: %s", applet,
234236
strerror (errno));
235237
return -1;
236238
}
237239
readfd = openat(dirfd, name, readflags);
238240
if (readfd == -1) {
241+
free(name);
239242
eerror("%s: unable to open directory: %s", applet,
240243
strerror(errno));
241244
return -1;
@@ -248,18 +251,23 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
248251
r = mkfifo(path, mode);
249252
umask(u);
250253
if (r == -1 && errno != EEXIST) {
254+
free(name);
251255
eerror("%s: mkfifo: %s", applet,
252256
strerror (errno));
253257
return -1;
254258
}
255259
readfd = openat(dirfd, name, readflags);
256260
if (readfd == -1) {
261+
free(name);
257262
eerror("%s: unable to open fifo: %s", applet,
258263
strerror(errno));
259264
return -1;
260265
}
261266
}
262267
}
268+
269+
free(name);
270+
263271
if (fstat(readfd, &st) != -1) {
264272
if (type != inode_dir && S_ISDIR(st.st_mode)) {
265273
eerror("%s: is a directory", path);

0 commit comments

Comments
 (0)