From c48748ba0929a488437d85732032aef78528093b Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 27 Dec 2017 12:18:28 +0100 Subject: ChannelEndPoint.cpp: re-scope/improve getSpec --- nxcomp/src/ChannelEndPoint.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'nxcomp/src/ChannelEndPoint.cpp') diff --git a/nxcomp/src/ChannelEndPoint.cpp b/nxcomp/src/ChannelEndPoint.cpp index a1d96086a..2abc0ee6a 100644 --- a/nxcomp/src/ChannelEndPoint.cpp +++ b/nxcomp/src/ChannelEndPoint.cpp @@ -113,13 +113,19 @@ ChannelEndPoint::setSpec(const char *hostName, long port) { bool ChannelEndPoint::getSpec(char **socketUri) const { - if (socketUri) *socketUri = NULL; + if (socketUri) + { + *socketUri = NULL; + } + else + { + return false; + } char *unixPath = NULL; char *hostName = NULL; long port = -1; - char *newSocketUri = NULL; int length = -1; if (getUnixPath(&unixPath)) @@ -133,17 +139,21 @@ ChannelEndPoint::getSpec(char **socketUri) const { if (length > 0) { - newSocketUri = static_cast(calloc(length + 1, sizeof(char))); - if (isUnixSocket()) - snprintf(newSocketUri, length+1, "unix:%s", unixPath); - else - snprintf(newSocketUri, length+1, "tcp:%s:%ld", hostName, port); + char *newSocketUri = static_cast(calloc(length + 1, sizeof(char))); + + if (newSocketUri) + { + if (isUnixSocket()) + snprintf(newSocketUri, length+1, "unix:%s", unixPath); + else + snprintf(newSocketUri, length+1, "tcp:%s:%ld", hostName, port); - if (socketUri) *socketUri = strdup(newSocketUri); + + SAFE_FREE(newSocketUri); + } } - SAFE_FREE(newSocketUri); SAFE_FREE(unixPath); SAFE_FREE(hostName); -- cgit v1.2.3 From eae64c4a4282eb2b511ba11c6db51d00a3b49833 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 27 Dec 2017 17:06:43 +0100 Subject: ChannelEndPoint.cpp: fix another memleak ==7689== 50 bytes in 5 blocks are definitely lost in loss record 1 of 2 ==7689== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==7689== by 0x54074D9: strndup (strndup.c:43) ==7689== by 0x4E7D803: ChannelEndPoint::getTCPHostAndPort(char**, long*) const (ChannelEndPoint.cpp:309) ==7689== by 0x4EC9D93: ConnectToRemote(ChannelEndPoint&) [clone .constprop.144] (Loop.cpp:6660) ==7689== by 0x4ECB94E: SetupProxyConnection() (Loop.cpp:3204) ==7689== by 0x4ECE824: handleNegotiationInLoop(int&, fd_set&, fd_set&, timeval&) [clone .isra.129] (Loop.cpp:14312) ==7689== by 0x4ED0F8A: NXTransPrepare (Loop.cpp:2575) ==7689== by 0x4ED1C35: NXTransContinue (Loop.cpp:1609) ==7689== by 0x4ED1D7B: WaitCleanup() (Loop.cpp:4440) ==7689== by 0x4ED2343: NXTransProxy (Loop.cpp:1234) ==7689== by 0x400B2A: main (Main.c:111) --- nxcomp/src/ChannelEndPoint.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'nxcomp/src/ChannelEndPoint.cpp') diff --git a/nxcomp/src/ChannelEndPoint.cpp b/nxcomp/src/ChannelEndPoint.cpp index 2abc0ee6a..de881835c 100644 --- a/nxcomp/src/ChannelEndPoint.cpp +++ b/nxcomp/src/ChannelEndPoint.cpp @@ -273,8 +273,10 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const { char *h = NULL; ssize_t h_len; - if (host) *host = NULL; - if (port) *port = 0; + if (host) + *host = NULL; + if (port) + *port = 0; if (getPort(&p)) { h_len = 0; -- cgit v1.2.3 From 17d045826ba98a55696cc56ebf6b56c811bf5392 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 27 Dec 2017 19:15:23 +0100 Subject: ChannelEndPoint.cpp: remove unneccessary code SAFE_FREE has set defaultUnixPath_ to NULL already --- nxcomp/src/ChannelEndPoint.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'nxcomp/src/ChannelEndPoint.cpp') diff --git a/nxcomp/src/ChannelEndPoint.cpp b/nxcomp/src/ChannelEndPoint.cpp index de881835c..443c0f290 100644 --- a/nxcomp/src/ChannelEndPoint.cpp +++ b/nxcomp/src/ChannelEndPoint.cpp @@ -180,8 +180,6 @@ ChannelEndPoint::setDefaultUnixPath(char *path) { if (path && strlen(path)) defaultUnixPath_ = strdup(path); - else - defaultUnixPath_ = NULL; isUnix_ = getUnixPath(); } -- cgit v1.2.3 From ce293647d5a63726c05260ca0e0f65a50e604ebb Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 27 Dec 2017 19:16:15 +0100 Subject: ChannelEndPoint.cpp: fix possible memleak in getUnixPath() --- nxcomp/src/ChannelEndPoint.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'nxcomp/src/ChannelEndPoint.cpp') diff --git a/nxcomp/src/ChannelEndPoint.cpp b/nxcomp/src/ChannelEndPoint.cpp index 443c0f290..7768df137 100644 --- a/nxcomp/src/ChannelEndPoint.cpp +++ b/nxcomp/src/ChannelEndPoint.cpp @@ -207,7 +207,10 @@ ChannelEndPoint::getPort(long *port) const { bool ChannelEndPoint::getUnixPath(char **unixPath) const { - if (unixPath) *unixPath = NULL; + if (unixPath) + *unixPath = NULL; + else + return false; long p; char *path = NULL; @@ -227,8 +230,7 @@ ChannelEndPoint::getUnixPath(char **unixPath) const { return false; } - if (unixPath) - *unixPath = strdup(path); + *unixPath = strdup(path); return true; } -- cgit v1.2.3