1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.
This commit is contained in:
Nobuyoshi Nakada 2020-01-20 09:30:17 +09:00
parent 884897dbe2
commit bdef392ec6
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

6
dir.c
View file

@ -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]),