http://hg.vergenet.net/vanessa/vanessa_socket/rev/86186acdf27e# HG changeset patch
# User Simon Horman <horms@verge.net.au>
# Date 1305777845 -32400
# Node ID 86186acdf27ef7dca5f927448c1a07126f491caa
# Parent f09d51ca6e578d74b99da38f0ddf563e44e32af5
Use freeaddrinfo() in on success in vanessa_socket_server_bind()
This resolves a memory leak
Signed-off-by: Simon Horman <horms@verge.net.au>
--- a/libvanessa_socket/vanessa_socket_server.c
Tue Oct 06 16:17:48 2009 +1100
+++ b/libvanessa_socket/vanessa_socket_server.c
Thu May 19 13:04:05 2011 +0900
@@ -110,6 +110,7 @@
goto err_close;
continue;
}
+
freeaddrinfo(res);
return s;
} while ((res = res->ai_next));
@@ -353,7 +354,7 @@
const unsigned int maximum_connections,
struct sockaddr *return_from,
struct sockaddr *return_to,
-
vanessa_socket_flag_t flag)
+
vanessa_socket_flag_t flag, long opt)
{
unsigned int addrlen;
pid_t child = 0;
@@ -370,7 +371,8 @@
if(errno == EINTR || errno == ECONNABORTED) {
continue; /* Ignore EINTR and ECONNABORTED */
0K .
}
-
if (errno == EAGAIN || errno == EWOULDBLOCK)
+
if (opt & O_NONBLOCK &&
+
(errno == EAGAIN || errno == EWOULDBLOCK))
return -1; /* Don't log EAGAIN or EWOULDBLOCK */
VANESSA_LOGGER_DEBUG_ERRNO("accept");
return(-1);
@@ -447,12 +449,19 @@
{
pid_t child;
int g;
+
long opt;
+
+
opt = fcntl(listen_socket, F_GETFL, NULL);
+
if (opt < 0) {
+
VANESSA_LOGGER_DEBUG_ERRNO("fcntl: F_GETFL");
+
return -1;
+
}
while (1) {
child = __vanessa_socket_server_accept(&g, listen_socket, NULL,
maximum_connections,
return_from, return_to,
-
flag);
+
flag, opt);
if (child < 0) {
VANESSA_LOGGER_DEBUG("__vanessa_socket_server_accept");
return -1;
@@ -527,14 +536,14 @@
listen_socketv,
maximum_connections,
return_from, return_to,
-
flag);
+
flag, opt);
if (child < 0) {
-
if (errno == EAGAIN || errno == EWOULDBLOCK)
-
status = 0;
-
else {
+
status = -1;
+
if (errno == EAGAIN || errno == EWOULDBLOCK) {
.+
if (opt & O_NONBLOCK)
+
status = 0;
+
} else
VANESSA_LOGGER_DEBUG("__vanessa_socket_server_accept");
-
status = -1;
-
}
}
if (!(opt & O_NONBLOCK) && child &&
@@ -607,6 +616,8 @@
maximum_connections,
return_from, return_to, flag);
if (child < 0) {
+
if (errno == EAGAIN || errno == EWOULDBLOCK)
+
continue;
VANESSA_LOGGER_DEBUG(
"__vanessa_socket_server_acceptv");
goto err;
15.5K=0.2s
2015-03-07 14:35:50 (15.5 KB/s) - written to stdout [2509]