Skip to content

Commit 18ae8d6

Browse files
Mikhail Dmitrichenkonobu
authored andcommitted
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>
1 parent 4ed7fa5 commit 18ae8d6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

dir.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2803,8 +2803,10 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc)
28032803
}
28042804
if (count >= capacity) {
28052805
capacity += 256;
2806-
if (!(newp = GLOB_REALLOC_N(ent->sort.entries, capacity)))
2806+
if (!(newp = GLOB_REALLOC_N(ent->sort.entries, capacity))) {
2807+
GLOB_FREE(rdp);
28072808
goto nomem;
2809+
}
28082810
ent->sort.entries = newp;
28092811
}
28102812
ent->sort.entries[count++] = rdp;

0 commit comments

Comments
 (0)