[前][次][番号順一覧][スレッド一覧]

ruby-changes:40061

From: nobu <ko1@a...>
Date: Sat, 17 Oct 2015 08:24:53 +0900 (JST)
Subject: [ruby-changes:40061] nobu:r52142 (trunk): ruby.c: fd leak

nobu	2015-10-17 08:24:37 +0900 (Sat, 17 Oct 2015)

  New Revision: 52142

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52142

  Log:
    ruby.c: fd leak
    
    * ruby.c (load_file_internal): fix potential fd leak.

  Modified files:
    trunk/ruby.c
Index: ruby.c
===================================================================
--- ruby.c	(revision 52141)
+++ ruby.c	(revision 52142)
@@ -1760,11 +1760,11 @@ load_file_internal(VALUE arg) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1760
 #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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]