From bdef392ec66168578053fabf8a81de48fd9e980c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 20 Jan 2020 09:30:17 +0900 Subject: Fixed double closedir In the case that shinking the entries buffer to the exact size failed, `dirp` is already closed. Found by mame with Coverity Scan. --- dir.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index d54ba646e4..0957800070 100644 --- a/dir.c +++ b/dir.c @@ -2252,8 +2252,10 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc) } closedir(dirp); if (count < capacity) { - if (!(newp = GLOB_REALLOC_N(ent->sort.entries, count))) - goto nomem; + if (!(newp = GLOB_REALLOC_N(ent->sort.entries, count))) { + glob_dir_finish(ent, 0); + return NULL; + } ent->sort.entries = newp; } ruby_qsort(ent->sort.entries, ent->sort.count, sizeof(ent->sort.entries[0]), -- cgit v1.2.3