diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-21 17:17:08 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-21 17:17:08 +0000 |
commit | 6d0b1d8a8691460189caee88bfbef2dd129b48bd (patch) | |
tree | be892e3518f0b5f0a0555cd9c996e62ccab5e5ba /file.c | |
parent | 10957cd1cc65dfa5c0c8d1f5d96caa8ac787467c (diff) |
merge revision(s) 49661,49662,49664:
test_file_exhaustive.rb: remove useless assignment
* test/ruby/test_file_exhaustive.rb (make_tmp_filename): not
assign to instance variable, @hardlinkfile.
* file.c (rb_file_identical_p): fix handle leak, ensure to close
the handle of the first argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -1052,6 +1052,25 @@ w32_io_info(VALUE *file, BY_HANDLE_FILE_INFORMATION *st) if (ret) CloseHandle(ret); return INVALID_HANDLE_VALUE; } + +static VALUE +close_handle(VALUE h) +{ + CloseHandle((HANDLE)h); + return Qfalse; +} + +struct w32_io_info_args { + VALUE *fname; + BY_HANDLE_FILE_INFORMATION *st; +}; + +static VALUE +call_w32_io_info(VALUE arg) +{ + struct w32_io_info_args *p = (void *)arg; + return (VALUE)w32_io_info(p->fname, p->st); +} #endif /* @@ -1915,8 +1934,15 @@ rb_file_identical_p(VALUE obj, VALUE fname1, VALUE fname2) # ifdef _WIN32 f1 = w32_io_info(&fname1, &st1); if (f1 == INVALID_HANDLE_VALUE) return Qfalse; - f2 = w32_io_info(&fname2, &st2); - if (f1) CloseHandle(f1); + if (f1) { + struct w32_io_info_args arg; + arg.fname = &fname2; + arg.st = &st2; + f2 = (HANDLE)rb_ensure(call_w32_io_info, (VALUE)&arg, close_handle, (VALUE)f1); + } + else { + f2 = w32_io_info(&fname2, &st2); + } if (f2 == INVALID_HANDLE_VALUE) return Qfalse; if (f2) CloseHandle(f2); |