diff options
| author | Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com> | 2026-05-05 17:19:25 +0300 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu.nakada@gmail.com> | 2026-05-07 20:42:56 +0900 |
| commit | 18ae8d6deda99d9f5bf5d372c27a72f95d1f7948 (patch) | |
| tree | 1c91ebf94f05cc03c075b5c90a3e58a017b362e6 | |
| parent | 4ed7fa5e4c0177d9e4be96f761d7b2b2d8974eda (diff) | |
dir.c: fix dirent leak on glob_opendir realloc failure
In glob_opendir(), each directory entry is copied before the entries
array is grown. If growing ent->sort.entries fails, the function jumps
to the nomem label before the copied entry is stored in the array.
glob_dir_finish() only frees entries already recorded in
ent->sort.entries, so the current rdp is leaked on that error path.
Free rdp before jumping to nomem.
Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
| -rw-r--r-- | dir.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -2803,8 +2803,10 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc) } if (count >= capacity) { capacity += 256; - if (!(newp = GLOB_REALLOC_N(ent->sort.entries, capacity))) + if (!(newp = GLOB_REALLOC_N(ent->sort.entries, capacity))) { + GLOB_FREE(rdp); goto nomem; + } ent->sort.entries = newp; } ent->sort.entries[count++] = rdp; |
