Subject: Re: [PATCH 1/3] connect.c: Fix memory leak

From: Junio C Hamano <[email-masked]>
Date: Tue, 10 Mar 2015 15:35:50 -0700

Stefan Beller <[email-masked]> writes:

> Signed-off-by: Stefan Beller <[email-masked]>
> ---
>  connect.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/connect.c b/connect.c
> index ce0e121..6090211 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -739,6 +739,7 @@ struct child_process *git_connect(int fd[2], const char *url,
>  
>  				free(hostandport);
>  				free(path);
> +				free(conn);
>  				return NULL;

The lack of sufficient context in the patch made me wonder if merely
freeing conn is sufficient or do we need some process related
clean-up before freeing it.

It appears that this codepath is used only when debugging with
CONNECT_DIAG_URL and we didn't start any process --- we only
cleared it with a few arrays initialized to empty at this point of
the code.

So it should be safe.  I wish I didn't have to do the digging
myself, though ;-)

>  			} else {
>  				ssh = getenv("GIT_SSH_COMMAND");