From ca872c9a9fda7db3081b03cef01a4e97455e9a30 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Tue, 6 Jan 2015 13:07:15 +0100 Subject: [PATCH] Fixed memory leaks --- CHANGES | 3 +++ socat.c | 8 ++++++++ xio-ipapp.c | 10 +++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 2822847..6b732e9 100644 --- a/CHANGES +++ b/CHANGES @@ -75,6 +75,9 @@ corrections: Socat did not work in FIPS mode because 1024 instead of 512 bit DH prime is required. Thanks to Zhigang Wang for reporting and sending a patch. + Christophe Leroy provided a patch that fixes memory leaks reported by + valgrind + porting: Socat included instead of POSIX Thanks to John Spencer for reporting this issue. diff --git a/socat.c b/socat.c index e802b8a..daa07d9 100644 --- a/socat.c +++ b/socat.c @@ -790,6 +790,7 @@ int _socat(void) { if (total_timeout.tv_sec < 0 || total_timeout.tv_sec == 0 && total_timeout.tv_usec < 0) { Notice("inactivity timeout triggered"); + free(buff); return 0; } } @@ -902,6 +903,7 @@ int _socat(void) { fds[0].fd, fds[0].events, fds[1].fd, fds[1].events, fds[2].fd, fds[2].events, fds[3].fd, fds[3].events, timeout.tv_sec, timeout.tv_usec, strerror(errno)); + free(buff); return -1; } else if (retval == 0) { Info2("poll timed out (no data within %ld.%06ld seconds)", @@ -923,6 +925,7 @@ int _socat(void) { socat_opts.total_timeout.tv_usec != 0) { /* there was a total inactivity timeout */ Notice("inactivity timeout triggered"); + free(buff); return 0; } @@ -941,6 +944,7 @@ int _socat(void) { named pipe. a read() might imm. return with 0 bytes, resulting in a loop? */ Error1("poll(...[%d]: invalid request", fd1in->fd); + free(buff); return -1; } mayrd1 = true; @@ -949,6 +953,7 @@ int _socat(void) { (fd2in->revents)) { if (fd2in->revents & POLLNVAL) { Error1("poll(...[%d]: invalid request", fd2in->fd); + free(buff); return -1; } mayrd2 = true; @@ -956,6 +961,7 @@ int _socat(void) { if (XIO_GETWRFD(sock1) >= 0 && fd1out->fd >= 0 && fd1out->revents) { if (fd1out->revents & POLLNVAL) { Error1("poll(...[%d]: invalid request", fd1out->fd); + free(buff); return -1; } maywr1 = true; @@ -963,6 +969,7 @@ int _socat(void) { if (XIO_GETWRFD(sock2) >= 0 && fd2out->fd >= 0 && fd2out->revents) { if (fd2out->revents & POLLNVAL) { Error1("poll(...[%d]: invalid request", fd2out->fd); + free(buff); return -1; } maywr2 = true; @@ -1088,6 +1095,7 @@ int _socat(void) { xioclose(sock1); xioclose(sock2); + free(buff); return 0; } diff --git a/xio-ipapp.c b/xio-ipapp.c index fe81399..eeb18f1 100644 --- a/xio-ipapp.c +++ b/xio-ipapp.c @@ -1,5 +1,5 @@ /* source: xio-ipapp.c */ -/* Copyright Gerhard Rieger 2001-2008 */ +/* Copyright Gerhard Rieger */ /* Published under the GNU General Public License V.2, see file COPYING */ /* this file contains the source for TCP and UDP related options */ @@ -92,12 +92,13 @@ int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts, if (result == STAT_RETRYLATER) { Nanosleep(&xfd->intervall, NULL); } - dropopts(opts, PH_ALL); opts = copyopts(opts0, GROUP_ALL); + dropopts(opts, PH_ALL); free(opts); opts = copyopts(opts0, GROUP_ALL); continue; } return STAT_NORETRY; #endif /* WITH_RETRY */ default: + free(opts0);free(opts); return result; } @@ -113,6 +114,7 @@ int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts, if (xfd->forever || --xfd->retry) { Nanosleep(&xfd->intervall, NULL); continue; } + free(opts0); return STAT_RETRYLATER; } @@ -125,7 +127,7 @@ int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts, Close(xfd->fd); /* with and without retry */ Nanosleep(&xfd->intervall, NULL); - dropopts(opts, PH_ALL); opts = copyopts(opts0, GROUP_ALL); + dropopts(opts, PH_ALL); free(opts); opts = copyopts(opts0, GROUP_ALL); continue; /* with next socket() bind() connect() */ } else #endif /* WITH_RETRY */ @@ -136,8 +138,10 @@ int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts, /* only "active" process breaks (master without fork, or child) */ if ((result = _xio_openlate(xfd, opts)) < 0) { + free(opts0);free(opts); return result; } + free(opts0);free(opts); return 0; }