Re: [PATCH v2 1/2] Clean stale environment pointer in finish_command()
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Nov 10, 2014, 14:41 UTC
- Message-ID
- <alpine.DEB.1.00.1411101539091.13845@s15462909.onlinehome-server.info>
- In-Reply-To
- <df1b16208e443416f7185c8c8c110e637ea97ac4.1415630072.git.johannes.schindelin@gmx.de>
Hi,
On Mon, 10 Nov 2014, Johannes Schindelin wrote:
Show 8 quoted lines
> In start_command(), unset "env" fields are initialized via "env_array". In > finish_command(), the "env_array" is cleared, therefore the "env" field > will point to free()d data. > > However, start_command() will set "env" to env_array.argv only if "env" > was unset to begin with, and if it was already set, the caller will need > the original value. Therefore, we need to be very careful only to reset > "env" in finish_command() when it has been initialized in start_command().
In case it was unclear: this is needed for the the suggested switch from the previous method to construct the environment to the new env_array method to work.
(The env_array method unfortunately requires the code to initialize the environment twice because finish_command() insists on always releasing the env_array, even if the caller may want to reuse the generated array).
Ciao, Johannes