ls: fix a small mem leak when CLI args have errors

$ valgrind --quiet --leak-check=full --show-leak-kinds=definite \
    src/ls --hyperlink=always foo bar
  ls: cannot access 'foo': No such file or directory
  ls: cannot access 'bar': No such file or directory

    32 bytes in 1 blocks are definitely lost in loss record 3 of 7
    at malloc (vg_replace_malloc.c:447)
    by canonicalize_filename_mode_stk (canonicalize.c:450)
    by canonicalize_filename_mode (canonicalize.c:471)
    by gobble_file.constprop.0 (ls.c:3392)
    by main (ls.c:1765)

* src/ls.c (gobble_file): Call free_ent() before returning.
This commit is contained in:
Pádraig Brady committed 2026-07-24 13:35:30 +01:00
1 parent 8f7ed6cf50
commit 1f681f8a72
1 file changed
+4 -1
+4 -1
View File
@@ -3464,7 +3464,10 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
_("cannot access %s"), full_name);
if (command_line_arg)
return 0;
{
free_ent (f);
return 0;
}
f->name = xstrdup (name);
cwd_n_used++;