Subject: Re: bug#32604: 26.1.50; memory leak in connect_network_socket

From: Noam Postavsky <[email-masked]>
Date: Sun, 02 Sep 2018 13:55:46 -0400

YAMAMOTO Mitsuharu <[email-masked]> writes:

> In connect_network_socket (in process.c), the memory pointed to
> by the variable `sa’ doesn’t seem to be deallocated.
>
>   3328	  struct sockaddr *sa = NULL;
> 	:
>   3347	  while (!NILP (addrinfos))
>   3348	    {
> 	:
>   3359	      if (sa)
>   3360		free (sa);
>   3361	      sa = xmalloc (addrlen);
> 	:
>   3533	    }
> 	:
>
> The following patch would fix the leak:

> +  xfree (sa);

I think we would need

    record_unwind_protect_ptr (xfree, sa);

to handle the case where an error is signaled.  Similar to how the
socket closing is handled:

      /* Make us close S if quit.  */
      record_unwind_protect_int (close_file_unwind, s);