From: sos AT prospect DOT com DOT ru (Sergey Okhapkin) Subject: RE: spawn memory leak? 7 Jun 1998 13:36:59 -0700 Message-ID: <01BD9273.355A3300.cygnus.cygwin32.developers@sos> To: "'Tim Newsham'" Cc: "cygwin32-developers AT cygnus DOT com" Tim Newsham wrote: > For those who cry "this only works for cygwin processes!", yes, true, > but it is better than not working at all. BUT... there seems to be > a way to do close-on-exec even when spawn()'ing non cygwin programs: > > foreach close-on-exec fd > save old handle flags > set handle flag to non-inheritable > build new fd table for child process without entries for these fd's > CreateProcess, passing down new table (not simply passing dup of parents) > foreach close-on-exec fd > set handle flag to saved value > > this of course only works on systems that support the SetHandleInformation > call, but imo, its better than not supporting it on any system at all. > I see another simple solution - functions pinfo::init_from_exec() and hinfo_vec::dup_for_exec() should be removed, and hinfo_vec::linearize_fd_array() should be modified to ignore fds with close_on_exec set. The single line will be modified (hinfo.cc, line 413): from if (vec[i].is_open ()) to if (vec[i].is_open () && !vec[i].h->get_close_on_exec ()) This will solve a problem with a failing spawn()/exec() also. But one more problem will arise - the os handles of these fds will be inheritted by spawned child :-( Probably, it would be better to leave linearize_fd_array unchanged an handle these fds in a child's delinearization code? -- Sergey Okhapkin, http://www.lexa.ru/sos Moscow, Russia