summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-16 23:24:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-16 23:24:37 +0000
commit34b877e49166c209e300ee9887f79b26b82821fc (patch)
tree197974441c6b3d31871586557d2a72a8404cb0a5 /ruby.c
parent7a8a49d98a15be3a132269ec83eebaedba32dcfe (diff)
ruby.c: fd leak
* ruby.c (load_file_internal): fix potential fd leak. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ruby.c b/ruby.c
index 6899ac2..8267002 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1760,11 +1760,11 @@ load_file_internal(VALUE arg)
#if !defined DOSISH && !defined __CYGWIN__
{
struct stat st;
- if (fstat(fd, &st) != 0)
- rb_load_fail(fname_v, strerror(errno));
- if (S_ISDIR(st.st_mode)) {
- errno = EISDIR;
- rb_load_fail(fname_v, strerror(EISDIR));
+ int e;
+ if ((fstat(fd, &st) != 0) && (e = errno, 1) ||
+ (S_ISDIR(st.st_mode) && (e = EISDIR, 1))) {
+ (void)close(fd);
+ rb_load_fail(fname_v, strerror(e));
}
}
#endif