Fixed memory leaks

This commit is contained in:
Gerhard Rieger 2015-01-06 13:07:15 +01:00
parent 281d1bd651
commit ca872c9a9f
3 changed files with 18 additions and 3 deletions

View File

@ -75,6 +75,9 @@ corrections:
Socat did not work in FIPS mode because 1024 instead of 512 bit DH prime 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. 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: porting:
Socat included <sys/poll.h> instead of POSIX <poll.h> Socat included <sys/poll.h> instead of POSIX <poll.h>
Thanks to John Spencer for reporting this issue. Thanks to John Spencer for reporting this issue.

View File

@ -790,6 +790,7 @@ int _socat(void) {
if (total_timeout.tv_sec < 0 || if (total_timeout.tv_sec < 0 ||
total_timeout.tv_sec == 0 && total_timeout.tv_usec < 0) { total_timeout.tv_sec == 0 && total_timeout.tv_usec < 0) {
Notice("inactivity timeout triggered"); Notice("inactivity timeout triggered");
free(buff);
return 0; return 0;
} }
} }
@ -902,6 +903,7 @@ int _socat(void) {
fds[0].fd, fds[0].events, fds[1].fd, fds[1].events, fds[0].fd, fds[0].events, fds[1].fd, fds[1].events,
fds[2].fd, fds[2].events, fds[3].fd, fds[3].events, fds[2].fd, fds[2].events, fds[3].fd, fds[3].events,
timeout.tv_sec, timeout.tv_usec, strerror(errno)); timeout.tv_sec, timeout.tv_usec, strerror(errno));
free(buff);
return -1; return -1;
} else if (retval == 0) { } else if (retval == 0) {
Info2("poll timed out (no data within %ld.%06ld seconds)", Info2("poll timed out (no data within %ld.%06ld seconds)",
@ -923,6 +925,7 @@ int _socat(void) {
socat_opts.total_timeout.tv_usec != 0) { socat_opts.total_timeout.tv_usec != 0) {
/* there was a total inactivity timeout */ /* there was a total inactivity timeout */
Notice("inactivity timeout triggered"); Notice("inactivity timeout triggered");
free(buff);
return 0; return 0;
} }
@ -941,6 +944,7 @@ int _socat(void) {
named pipe. a read() might imm. return with 0 bytes, resulting named pipe. a read() might imm. return with 0 bytes, resulting
in a loop? */ in a loop? */
Error1("poll(...[%d]: invalid request", fd1in->fd); Error1("poll(...[%d]: invalid request", fd1in->fd);
free(buff);
return -1; return -1;
} }
mayrd1 = true; mayrd1 = true;
@ -949,6 +953,7 @@ int _socat(void) {
(fd2in->revents)) { (fd2in->revents)) {
if (fd2in->revents & POLLNVAL) { if (fd2in->revents & POLLNVAL) {
Error1("poll(...[%d]: invalid request", fd2in->fd); Error1("poll(...[%d]: invalid request", fd2in->fd);
free(buff);
return -1; return -1;
} }
mayrd2 = true; mayrd2 = true;
@ -956,6 +961,7 @@ int _socat(void) {
if (XIO_GETWRFD(sock1) >= 0 && fd1out->fd >= 0 && fd1out->revents) { if (XIO_GETWRFD(sock1) >= 0 && fd1out->fd >= 0 && fd1out->revents) {
if (fd1out->revents & POLLNVAL) { if (fd1out->revents & POLLNVAL) {
Error1("poll(...[%d]: invalid request", fd1out->fd); Error1("poll(...[%d]: invalid request", fd1out->fd);
free(buff);
return -1; return -1;
} }
maywr1 = true; maywr1 = true;
@ -963,6 +969,7 @@ int _socat(void) {
if (XIO_GETWRFD(sock2) >= 0 && fd2out->fd >= 0 && fd2out->revents) { if (XIO_GETWRFD(sock2) >= 0 && fd2out->fd >= 0 && fd2out->revents) {
if (fd2out->revents & POLLNVAL) { if (fd2out->revents & POLLNVAL) {
Error1("poll(...[%d]: invalid request", fd2out->fd); Error1("poll(...[%d]: invalid request", fd2out->fd);
free(buff);
return -1; return -1;
} }
maywr2 = true; maywr2 = true;
@ -1088,6 +1095,7 @@ int _socat(void) {
xioclose(sock1); xioclose(sock1);
xioclose(sock2); xioclose(sock2);
free(buff);
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* source: xio-ipapp.c */ /* source: xio-ipapp.c */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
/* this file contains the source for TCP and UDP related options */ /* 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) { if (result == STAT_RETRYLATER) {
Nanosleep(&xfd->intervall, NULL); 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; continue;
} }
return STAT_NORETRY; return STAT_NORETRY;
#endif /* WITH_RETRY */ #endif /* WITH_RETRY */
default: default:
free(opts0);free(opts);
return result; return result;
} }
@ -113,6 +114,7 @@ int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts,
if (xfd->forever || --xfd->retry) { if (xfd->forever || --xfd->retry) {
Nanosleep(&xfd->intervall, NULL); continue; Nanosleep(&xfd->intervall, NULL); continue;
} }
free(opts0);
return STAT_RETRYLATER; return STAT_RETRYLATER;
} }
@ -125,7 +127,7 @@ int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts,
Close(xfd->fd); Close(xfd->fd);
/* with and without retry */ /* with and without retry */
Nanosleep(&xfd->intervall, NULL); 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() */ continue; /* with next socket() bind() connect() */
} else } else
#endif /* WITH_RETRY */ #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) */ /* only "active" process breaks (master without fork, or child) */
if ((result = _xio_openlate(xfd, opts)) < 0) { if ((result = _xio_openlate(xfd, opts)) < 0) {
free(opts0);free(opts);
return result; return result;
} }
free(opts0);free(opts);
return 0; return 0;
} }