public
Description: ruby lang (www.ruby-lang.org) svn mirror
Homepage: http://svn.ruby-lang.org/repos/ruby/
Clone URL: git://github.com/juretta/ruby.git
  * win32/win32.c (exit_handler): use st_free_table() to free socklist.

  * win32/win32.c (rb_w32_pipe_exec, rb_w32_accept, rb_w32_socket,
    rb_w32_socketpair): should check and release fd and sockets/handles
    if an error occurs in rb_w32_open_osfhandle().



git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18196 
b2dd03c8-39d4-4d8f-98ff-823fe69b080e
usa (author)
Thu Jul 24 00:33:00 -0700 2008
commit  0c5f365327f7d6f157612ffb32f2c5321cfe6872
tree    84c63f4c3610a660196daf2539ed5743b5680b68
parent  3c66b8fa08fc913bd5d5879887bd20ce4027b9d6
...
 
 
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1,3 +1,11 @@
0
+Thu Jul 24 16:30:21 2008 NAKAMURA Usaku <usa@ruby-lang.org>
0
+
0
+ * win32/win32.c (exit_handler): use st_free_table() to free socklist.
0
+
0
+ * win32/win32.c (rb_w32_pipe_exec, rb_w32_accept, rb_w32_socket,
0
+ rb_w32_socketpair): should check and release fd and sockets/handles
0
+ if an error occurs in rb_w32_open_osfhandle().
0
+
0
 Thu Jul 24 16:05:02 2008 NAKAMURA Usaku <usa@ruby-lang.org>
0
 
0
   * win32/win32.c (overlapped_socket_io): avoid warnings.
...
439
440
441
442
 
443
444
445
...
751
752
753
754
755
756
757
 
 
758
759
760
...
762
763
764
765
766
767
768
...
777
778
779
780
 
 
 
781
782
783
...
837
838
839
840
 
841
842
 
 
843
844
845
 
846
847
848
849
850
851
852
 
 
 
 
853
854
 
 
 
 
 
 
 
 
855
856
857
...
2272
2273
2274
2275
2276
 
 
 
 
2277
2278
2279
...
2629
2630
2631
2632
2633
 
 
 
 
2634
2635
2636
...
2850
2851
2852
2853
2854
2855
 
 
 
 
 
2856
 
 
 
 
 
 
 
2857
2858
2859
...
439
440
441
 
442
443
444
445
...
751
752
753
 
 
754
 
755
756
757
758
759
...
761
762
763
 
764
765
766
...
775
776
777
 
778
779
780
781
782
783
...
837
838
839
 
840
841
 
842
843
844
845
 
846
847
848
849
850
851
 
 
852
853
854
855
856
 
857
858
859
860
861
862
863
864
865
866
867
...
2282
2283
2284
 
2285
2286
2287
2288
2289
2290
2291
2292
...
2642
2643
2644
 
2645
2646
2647
2648
2649
2650
2651
2652
...
2866
2867
2868
 
 
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
0
@@ -439,7 +439,7 @@ exit_handler(void)
0
 {
0
     if (NtSocketsInitialized) {
0
   WSACleanup();
0
- xfree(socklist);
0
+ st_free_table(socklist);
0
   socklist = NULL;
0
   NtSocketsInitialized = 0;
0
     }
0
@@ -751,10 +751,9 @@ rb_w32_join_argv(char *cmd, char *const *argv)
0
     return cmd;
0
 }
0
 
0
-static int socketpair_internal(int af, int type, int protocol, SOCKET *sv);
0
-
0
 rb_pid_t
0
-rb_w32_pipe_exec(const char *cmd, const char *prog, int mode, int *pipe, int *write_pipe)
0
+rb_w32_pipe_exec(const char *cmd, const char *prog, int mode, int *pipe,
0
+ int *write_pipe)
0
 {
0
     struct ChildRecord* child;
0
     HANDLE hIn, hOut;
0
@@ -762,7 +761,6 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode, int *pipe, int *wr
0
     HANDLE hCurProc;
0
     SECURITY_ATTRIBUTES sa;
0
     BOOL reading, writing;
0
- int binmode;
0
     int ret;
0
 
0
     /* Figure out what we're doing... */
0
@@ -777,7 +775,9 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode, int *pipe, int *wr
0
   reading = TRUE;
0
   writing = FALSE;
0
     }
0
- binmode |= (mode & O_BINARY) ? O_BINARY : O_TEXT;
0
+ mode &= ~(O_RDWR|O_RDONLY|O_WRONLY);
0
+ if (!(mode & O_BINARY))
0
+ mode |= O_TEXT;
0
 
0
     sa.nLength = sizeof (SECURITY_ATTRIBUTES);
0
     sa.lpSecurityDescriptor = NULL;
0
@@ -837,21 +837,31 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode, int *pipe, int *wr
0
 
0
   /* associate handle to file descritor */
0
   if (reading) {
0
- *pipe = rb_w32_open_osfhandle((intptr_t)hDupIn, _O_RDONLY | binmode);
0
+ *pipe = rb_w32_open_osfhandle((intptr_t)hDupIn, O_RDONLY | mode);
0
    if (writing)
0
- *write_pipe = rb_w32_open_osfhandle((intptr_t)hDupOut, _O_WRONLY | binmode);
0
+ *write_pipe = rb_w32_open_osfhandle((intptr_t)hDupOut,
0
+ O_WRONLY | mode);
0
   }
0
   else {
0
- *pipe = rb_w32_open_osfhandle((intptr_t)hDupOut, _O_WRONLY | binmode);
0
+ *pipe = rb_w32_open_osfhandle((intptr_t)hDupOut, O_WRONLY | mode);
0
   }
0
   if (hIn)
0
    CloseHandle(hIn);
0
   if (hOut)
0
    CloseHandle(hOut);
0
- if (*pipe == -1) {
0
- if (hDupIn)
0
+ if (reading && writing && *write_pipe == -1) {
0
+ if (*pipe != -1)
0
+ rb_w32_close(*pipe);
0
+ else
0
     CloseHandle(hDupIn);
0
- if (hDupOut)
0
+ CloseHandle(hDupOut);
0
+ CloseChildHandle(child);
0
+ break;
0
+ }
0
+ else if (*pipe == -1) {
0
+ if (reading)
0
+ CloseHandle(hDupIn);
0
+ else
0
     CloseHandle(hDupOut);
0
    CloseChildHandle(child);
0
    break;
0
@@ -2272,8 +2282,11 @@ rb_w32_accept(int s, struct sockaddr *addr, int *addrlen)
0
    s = -1;
0
   }
0
   else {
0
- st_insert(socklist, (st_data_t)r, (st_data_t)0);
0
    s = rb_w32_open_osfhandle(r, O_RDWR|O_BINARY|O_NOINHERIT);
0
+ if (s != -1)
0
+ st_insert(socklist, (st_data_t)r, (st_data_t)0);
0
+ else
0
+ closesocket(r);
0
   }
0
     });
0
     return s;
0
@@ -2629,8 +2642,11 @@ rb_w32_socket(int af, int type, int protocol)
0
    fd = -1;
0
   }
0
   else {
0
- st_insert(socklist, (st_data_t)s, (st_data_t)0);
0
    fd = rb_w32_open_osfhandle(s, O_RDWR|O_BINARY|O_NOINHERIT);
0
+ if (fd != -1)
0
+ st_insert(socklist, (st_data_t)s, (st_data_t)0);
0
+ else
0
+ closesocket(s);
0
   }
0
     });
0
     return fd;
0
@@ -2850,10 +2866,20 @@ rb_w32_socketpair(int af, int type, int protocol, int *sv)
0
 
0
     if (socketpair_internal(af, type, protocol, pair) < 0)
0
   return -1;
0
- st_insert(socklist, (st_data_t)pair[0], (st_data_t)0);
0
- st_insert(socklist, (st_data_t)pair[1], (st_data_t)0);
0
     sv[0] = rb_w32_open_osfhandle(pair[0], O_RDWR|O_BINARY|O_NOINHERIT);
0
+ if (sv[0] == -1) {
0
+ closesocket(pair[0]);
0
+ closesocket(pair[1]);
0
+ return -1;
0
+ }
0
     sv[1] = rb_w32_open_osfhandle(pair[1], O_RDWR|O_BINARY|O_NOINHERIT);
0
+ if (sv[1] == -1) {
0
+ rb_w32_close(sv[0]);
0
+ closesocket(pair[1]);
0
+ return -1;
0
+ }
0
+ st_insert(socklist, (st_data_t)pair[0], (st_data_t)0);
0
+ st_insert(socklist, (st_data_t)pair[1], (st_data_t)0);
0
 
0
     return 0;
0
 }

Comments

    No one has commented yet.