From 1c09eab703de18430241a11abec0526512d851b9 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 28 Nov 2017 21:18:48 +0100 Subject: Loop.cpp: fix two memleaks --- nxcomp/src/Loop.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'nxcomp') diff --git a/nxcomp/src/Loop.cpp b/nxcomp/src/Loop.cpp index b51d7e7e3..ca9e5ed08 100644 --- a/nxcomp/src/Loop.cpp +++ b/nxcomp/src/Loop.cpp @@ -4278,15 +4278,20 @@ int ListenConnectionTCP(const char *host, long port, const char *label) int ListenConnection(ChannelEndPoint &endpoint, const char *label) { - char *unixPath, *host; + char *unixPath = NULL, *host = NULL; long port; + int result = -1; if (endpoint.getUnixPath(&unixPath)) { - return ListenConnectionUnix(unixPath, label); + result = ListenConnectionUnix(unixPath, label); } else if (endpoint.getTCPHostAndPort(&host, &port)) { - return ListenConnectionTCP(host, port, label); + result = ListenConnectionTCP(host, port, label); } - return -1; + free(unixPath); + unixPath = NULL; + free(host); + host = NULL; + return result; } static int AcceptConnection(int fd, int domain, const char *label) @@ -6739,10 +6744,20 @@ int ConnectToRemote(ChannelEndPoint &socketAddress) } } + free(unixPath); + unixPath = NULL; + free(hostName); + hostName = NULL; + return pFD; ConnectToRemoteError: + free(unixPath); + unixPath = NULL; + free(hostName); + hostName = NULL; + if (pFD != -1) { close(pFD); -- cgit v1.2.3