From: Junio C Hamano Date: Tue, 11 Nov 2014 15:55:43 GMT Subject: Re: [PATCH v2 1/2] Clean stale environment pointer in finish_command() Message-ID: In-Reply-To: <20141111031636.GE21328@peff.net> Jeff King writes: > I don't think this is "unfortunately"; freeing the memory was the entire > purpose in adding env_array. If you want to easily reuse the same > environment in multiple commands, it is still perfectly fine to use > "env" directly, like: > > struct argv_array env = ARGV_ARRAY_INIT; > struct child_process one = CHILD_PROCESS_INIT; > struct child_process two = CHILD_PROCESS_INIT; > > ... setup env with argv_array_push ... > > one.argv = foo; > one.env = env.argv; > run_command(&one); > > two.argv = bar; > two.env = env.argv; > run_command(&two); > > argv_array_clear(&env); > > You do not get the benefit of the auto-cleanup (you have to call > argv_array_clear yourself), but that is less bad than repeating the > setup of "env" twice. Yeah, the above looks like the best option, better than using a single child_process and having to re-initialize fds and envs. Thanks for helping.