aboutsummaryrefslogtreecommitdiff
path: root/nxcomp/src/Loop.cpp
diff options
context:
space:
mode:
authorMihai Moldovan <ionic@ionic.de>2017-12-09 13:16:37 +0100
committerMihai Moldovan <ionic@ionic.de>2017-12-09 13:16:37 +0100
commit804ff44523ab726fdb59b80193652465df0482ee (patch)
tree638d62dce7a3e1f4245cb53212e3e422f310be99 /nxcomp/src/Loop.cpp
parent6d7536bd4f5cad9a779c186bd2649b34ec71b367 (diff)
parent4dbee3a3f13657577f283bca22b281d7273c19e5 (diff)
downloadnx-libs-804ff44523ab726fdb59b80193652465df0482ee.tar.gz
nx-libs-804ff44523ab726fdb59b80193652465df0482ee.tar.bz2
nx-libs-804ff44523ab726fdb59b80193652465df0482ee.zip
Merge branch 'uli42-pr/fix_memleaks' into 3.6.x
Attributes GH PR #575: https://github.com/ArcticaProject/nx-libs/pull/575 Fixes: ArcticaProject/nx-libs#569 Fixes: ArcticaProject/nx-libs#573
Diffstat (limited to 'nxcomp/src/Loop.cpp')
-rw-r--r--nxcomp/src/Loop.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/nxcomp/src/Loop.cpp b/nxcomp/src/Loop.cpp
index b51d7e7e3..baad17699 100644
--- a/nxcomp/src/Loop.cpp
+++ b/nxcomp/src/Loop.cpp
@@ -3187,8 +3187,7 @@ int SetupProxyConnection()
nxinfo << "Loop: listenSocket is "<< ( listenSocket.enabled() ? "enabled" : "disabled") << ". "
<< "The socket URI is '"<< ( socketUri != NULL ? socketUri : "<unset>") << "'.\n" << std::flush;
- free(socketUri);
- socketUri = NULL;
+ SAFE_FREE(socketUri);
if (WE_INITIATE_CONNECTION)
{
@@ -3196,7 +3195,7 @@ int SetupProxyConnection()
{
nxinfo << "Loop: Going to connect to '" << socketUri
<< "'.\n" << std::flush;
- free(socketUri);
+ SAFE_FREE(socketUri);
proxyFD = ConnectToRemote(connectSocket);
@@ -3219,7 +3218,7 @@ int SetupProxyConnection()
{
nxinfo << "Loop: Going to wait for connection at '"
<< socketUri << "'.\n" << std::flush;
- free(socketUri);
+ SAFE_FREE(socketUri);
proxyFD = WaitForRemote(listenSocket);
@@ -4278,15 +4277,18 @@ 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;
+ SAFE_FREE(unixPath);
+ SAFE_FREE(host);
+ return result;
}
static int AcceptConnection(int fd, int domain, const char *label)
@@ -6217,7 +6219,7 @@ int WaitForRemote(ChannelEndPoint &socketAddress)
cerr << "Info" << ": Waiting for connection from "
<< hostLabel << " on socket '" << socketUri
<< "'.\n";
- free(socketUri);
+ SAFE_FREE(socketUri);
//
// How many times to loop waiting for connections
@@ -6306,7 +6308,7 @@ int WaitForRemote(ChannelEndPoint &socketAddress)
cerr << "Info" << ": Accepted connection from this host on Unix file socket '"
<< unixPath << "'.\n";
- free(unixPath);
+ SAFE_FREE(unixPath);
break;
}
@@ -6739,10 +6741,16 @@ int ConnectToRemote(ChannelEndPoint &socketAddress)
}
}
+ SAFE_FREE(unixPath);
+ SAFE_FREE(hostName);
+
return pFD;
ConnectToRemoteError:
+ SAFE_FREE(unixPath);
+ SAFE_FREE(hostName);
+
if (pFD != -1)
{
close(pFD);
@@ -7938,7 +7946,7 @@ int ParseEnvironmentOptions(const char *env, int force)
cerr << "Error" << ": Refusing 'listen' parameter with 'connect' being '"
<< socketUri << "'.\n";
- free(socketUri);
+ SAFE_FREE(socketUri);
return -1;
}
@@ -7966,7 +7974,7 @@ int ParseEnvironmentOptions(const char *env, int force)
cerr << "Error" << ": Refusing 'accept' parameter with 'connect' being '"
<< socketUri << "'.\n";
- free(socketUri);
+ SAFE_FREE(socketUri);
return -1;
}