summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/dir.c b/dir.c
index f7735df4eb..854bec6c08 100644
--- a/dir.c
+++ b/dir.c
@@ -445,6 +445,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
rb_encoding *fsenc;
VALUE dirname, opt, orig;
static ID keyword_ids[1];
+ const char *path;
if (!keyword_ids[0]) {
keyword_ids[0] = rb_intern("encoding");
@@ -472,13 +473,15 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
dp->dir = NULL;
dp->path = Qnil;
dp->enc = fsenc;
- dp->dir = opendir(RSTRING_PTR(dirname));
+ path = RSTRING_PTR(dirname);
+ dp->dir = opendir(path);
if (dp->dir == NULL) {
if (errno == EMFILE || errno == ENFILE) {
rb_gc();
- dp->dir = opendir(RSTRING_PTR(dirname));
+ dp->dir = opendir(path);
}
if (dp->dir == NULL) {
+ RB_GC_GUARD(dirname);
rb_sys_fail_path(orig);
}
}
@@ -1122,7 +1125,7 @@ do_opendir(const char *path, int flags, rb_encoding *enc)
{
DIR *dirp;
#ifdef _WIN32
- volatile VALUE tmp;
+ VALUE tmp = 0;
if (enc != rb_usascii_encoding() &&
enc != rb_ascii8bit_encoding() &&
enc != rb_utf8_encoding()) {
@@ -1134,6 +1137,9 @@ do_opendir(const char *path, int flags, rb_encoding *enc)
dirp = opendir(path);
if (dirp == NULL && !to_be_ignored(errno))
sys_warning(path);
+#ifdef _WIN32
+ if (tmp) rb_str_resize(tmp, 0); /* GC guard */
+#endif
return dirp;
}