From 1f71df7aacf15dbf242c74a4b7a7ac8fe0984a3c Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 31 Jan 2016 02:00:12 +0100 Subject: [PATCH] Fix segfault from double free * process.c (check_for_dns): Protect against double free issues. --- src/process.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/process.c b/src/process.c index 0fe45185361..a30dd23077c 100644 --- a/src/process.c +++ b/src/process.c @@ -4542,6 +4542,11 @@ check_for_dns (Lisp_Object proc) struct Lisp_Process *p = XPROCESS (proc); Lisp_Object ip_addresses = Qnil; int ret = 0; + int connect = 0; + + /* Sanity check. */ + if (! p->dns_requests) + return 1; ret = gai_error (p->dns_requests[0]); if (ret == EAI_INPROGRESS) @@ -4561,7 +4566,7 @@ check_for_dns (Lisp_Object proc) ip_addresses = Fnreverse (ip_addresses); freeaddrinfo (p->dns_requests[0]->ar_result); - connect_network_socket (proc, ip_addresses); + connect = 1; } else pset_status (p, Qfailed); @@ -4571,6 +4576,11 @@ check_for_dns (Lisp_Object proc) xfree ((void *)p->dns_requests[0]->ar_service); xfree (p->dns_requests[0]); xfree (p->dns_requests); + p->dns_requests = NULL; + + if (connect) + connect_network_socket (proc, ip_addresses); + return 1; } #endif /* HAVE_GETADDRINFO_A */ -- 2.39.5