changeset 1425:838f2687e9a2

Fixed a couple file descriptor leaks in dillo's DPI code
author Jorge Arellano Cid <jcid@dillo.org>
date Tue, 10 Nov 2009 17:42:41 -0300
parents 8535113920b1
children 8ee11f59a5ca
files dpi/bookmarks.c src/IO/dpi.c
diffstat 2 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/bookmarks.c	Mon Nov 09 14:22:27 2009 -0300
+++ b/dpi/bookmarks.c	Tue Nov 10 17:42:41 2009 -0300
@@ -1704,6 +1704,9 @@
    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 @@
          }
          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);
--- a/src/IO/dpi.c	Mon Nov 09 14:22:27 2009 -0300
+++ b/src/IO/dpi.c	Tue Nov 10 17:42:41 2009 -0300
@@ -389,6 +389,7 @@
       } else {
          ret = 0;
       }
+      Dpi_close_fd(st_pipe[0]);
    }
 
    return ret;
@@ -416,6 +417,8 @@
       SharedKey[i] = 0;
       ret = 1;
    }
+   if (In)
+      fclose(In);
    dFree(rcline);
    dFree(fname);
 
@@ -525,12 +528,10 @@
  *       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 @@
          ok = 1;
       }
       dFree(request);
-      shutdown(sock_fd, 1); /* signals no more writes to dpid */
    }
    if (ok) {
       /* Get the reply */
@@ -580,7 +580,6 @@
       } else {
          ok = 1;
       }
-      Dpi_close_fd(sock_fd);
    }
    if (ok) {
       /* Parse reply */
@@ -597,6 +596,7 @@
       dFree(cmd);
    }
    dFree(rply);
+   Dpi_close_fd(sock_fd);
 
    return ok ? dpi_port : -1;
 }