summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Dmitrichenko <m.dmitrichenko222@gmail.com>2026-05-05 17:19:25 +0300
committerNobuyoshi Nakada <nobu.nakada@gmail.com>2026-05-07 20:42:56 +0900
commit18ae8d6deda99d9f5bf5d372c27a72f95d1f7948 (patch)
tree1c91ebf94f05cc03c075b5c90a3e58a017b362e6
parent4ed7fa5e4c0177d9e4be96f761d7b2b2d8974eda (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.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index d81ae28ee9..9f2d36b633 100644
--- a/dir.c
+++ b/dir.c
@@ -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;