diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2009-11-10 17:42:41 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2009-11-10 17:42:41 -0300 |
commit | a39453a02f230683c480d7643b1ecfcd3a5ad7a2 (patch) | |
tree | afda5cebc26f780b77ebe52869f89e321a93267d | |
parent | 67cab0ec64e4b66793675f8e83c4820c5dbd9be3 (diff) |
Fixed a couple file descriptor leaks in dillo's DPI code
-rw-r--r-- | dpi/bookmarks.c | 9 | ||||
-rw-r--r-- | src/IO/dpi.c | 10 |
2 files changed, 11 insertions, 8 deletions
diff --git a/dpi/bookmarks.c b/dpi/bookmarks.c index 122c8c5e..a4d7c74b 100644 --- a/dpi/bookmarks.c +++ b/dpi/bookmarks.c @@ -1704,6 +1704,9 @@ int main(void) { if (signal (SIGTERM, termination_handler) == SIG_IGN) signal (SIGTERM, SIG_IGN); + /* We may receive SIGPIPE (e.g. socket is closed early by our client) */ + signal(SIGPIPE, SIG_IGN); + /* Initialize local data */ B_bms = dList_new(512); B_secs = dList_new(32); @@ -1740,10 +1743,10 @@ int main(void) { } dFree(tok); - if (code == 1) - exit(1); - else if (code == 2) + if (code != 0) { + /* socket is not operative (e.g. closed by client) */ break; + } } a_Dpip_dsh_close(sh); diff --git a/src/IO/dpi.c b/src/IO/dpi.c index 5834ab0f..6491ea27 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -389,6 +389,7 @@ static int Dpi_start_dpid(void) } else { ret = 0; } + Dpi_close_fd(st_pipe[0]); } return ret; @@ -416,6 +417,8 @@ static int Dpi_read_comm_keys(int *port) SharedKey[i] = 0; ret = 1; } + if (In) + fclose(In); dFree(rcline); dFree(fname); @@ -525,12 +528,10 @@ static int Dpi_blocking_start_dpid(void) * change at any time, we'll ask each time. If someday we find * that connecting each time significantly degrades performance, * an optimized approach can be tried. - * TODO: here we should use the credentials in ~/.dillo/dpid_comm_keys - * (dpid port and password). */ static int Dpi_get_server_port(const char *server_name) { - int sock_fd, dpi_port = -1; + int sock_fd = -1, dpi_port = -1; int dpid_port, ok = 0; struct sockaddr_in sin; char *cmd, *request, *rply = NULL, *port_str; @@ -570,7 +571,6 @@ static int Dpi_get_server_port(const char *server_name) ok = 1; } dFree(request); - shutdown(sock_fd, 1); /* signals no more writes to dpid */ } if (ok) { /* Get the reply */ @@ -580,7 +580,6 @@ static int Dpi_get_server_port(const char *server_name) } else { ok = 1; } - Dpi_close_fd(sock_fd); } if (ok) { /* Parse reply */ @@ -597,6 +596,7 @@ static int Dpi_get_server_port(const char *server_name) dFree(cmd); } dFree(rply); + Dpi_close_fd(sock_fd); return ok ? dpi_port : -1; } |