summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-20 09:30:17 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-20 09:49:27 +0900
commitbdef392ec66168578053fabf8a81de48fd9e980c (patch)
treeeee2f6c4046ab6c497fcb2f7234f3e7dea387a44 /dir.c
parent884897dbe20674d3a741cbfacac8cbca862675d0 (diff)
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.
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index d54ba64..0957800 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]),