1
0
mirror of https://github.com/moparisthebest/socat synced 2024-12-21 14:38:48 -05:00

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
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 <sys/poll.h> instead of POSIX <poll.h>
Thanks to John Spencer for reporting this issue.

View File

@ -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;
}

View File

@ -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;
}