diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2013-01-01 18:27:25 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2013-01-01 18:27:25 -0300 |
commit | 9a533c36c2858875a31900fc86a3000a8f1d59bc (patch) | |
tree | 2275ea59a085b8458d1b30ef61af35a56bd2b6a9 /src/IO/dpi.c | |
parent | 63a8894243214f850a3ec2d934822a633c8b7cd1 (diff) |
Don't leak a FD if write() fails on a just-connected local dpi socket.
This also fixes the wrong error message given in this situation.
http://lists.auriga.wearlab.de/pipermail/dillo-dev/2012-December/009656.html
Patch: p37sitdu, jcid
Diffstat (limited to 'src/IO/dpi.c')
-rw-r--r-- | src/IO/dpi.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/IO/dpi.c b/src/IO/dpi.c index 4b5a5aa2..24f1fce8 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -638,7 +638,7 @@ static int Dpi_connect_socket(const char *server_name) } else if (connect(sock_fd, (void*)&sin, sizeof(sin)) == -1) { MSG("[dpi::connect] errno:%d %s\n", errno, dStrerror(errno)); - /* send authentication Key (the server closes sock_fd on error) */ + /* send authentication Key (the server closes sock_fd on auth error) */ } else if (!(cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "auth", SharedKey))) { MSG_ERR("[Dpi_connect_socket] Can't make auth message.\n"); } else if (Dpi_blocking_write(sock_fd, cmd, strlen(cmd)) == -1) { @@ -647,6 +647,8 @@ static int Dpi_connect_socket(const char *server_name) ret = sock_fd; } dFree(cmd); + if (sock_fd != -1 && ret == -1) /* can't send cmd? */ + Dpi_close_fd(sock_fd); return ret; } @@ -668,20 +670,19 @@ void a_Dpi_ccc(int Op, int Branch, int Dir, ChainLink *Info, switch (Op) { case OpStart: if ((st = Dpi_blocking_start_dpid()) == 0) { - SockFD = Dpi_connect_socket(Data1); - if (SockFD != -1) { + if ((SockFD = Dpi_connect_socket(Data1)) != -1) { int *fd = dNew(int, 1); *fd = SockFD; Info->LocalKey = fd; a_Chain_link_new(Info, a_Dpi_ccc, BCK, a_IO_ccc, 1, 1); a_Chain_bcb(OpStart, Info, NULL, NULL); + /* Let the FD known and tracked */ + a_Chain_bcb(OpSend, Info, &SockFD, "FD"); + a_Chain_fcb(OpSend, Info, &SockFD, "FD"); + a_Chain_fcb(OpSend, Info, NULL, "DpidOK"); + } else { + a_Dpi_ccc(OpAbort, 1, FWD, Info, NULL, NULL); } - } - - if (st == 0 && SockFD != -1) { - a_Chain_bcb(OpSend, Info, &SockFD, "FD"); - a_Chain_fcb(OpSend, Info, &SockFD, "FD"); - a_Chain_fcb(OpSend, Info, NULL, "DpidOK"); } else { MSG_ERR("dpi.c: can't start dpi daemon\n"); a_Dpi_ccc(OpAbort, 1, FWD, Info, NULL, "DpidERROR"); |