]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
put bandaid on xmlrpc-c to not destroy the box for no reason
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 29 May 2008 01:23:14 +0000 (01:23 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 29 May 2008 01:23:14 +0000 (01:23 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8715 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/xmlrpc-c/lib/abyss/src/socket_unix.c

index 26fecf7f894f1e1c3b1832ce1e845e217b79603b..c3d2c81c63dd2f37148c85e950c6bcc6fdd40c0f 100644 (file)
@@ -40,7 +40,7 @@
 
 #include "socket_unix.h"
 
-
+#define sane_close(_it) if (_it > 0) {close(_it) ; _it = -1; }
 
 typedef struct {
     int interruptorFd;
@@ -50,19 +50,19 @@ typedef struct {
 
 
 static void
-initInterruptPipe(interruptPipe * const pipeP,
+initInterruptPipe(interruptPipe * pipeP,
                   const char **   const errorP) {
 
-    int pipeFd[2];
+    int pipeFd[2] = {-1, -1};
     int rc;
 
     rc = pipe(pipeFd);
 
-    if (rc != 0)
+    if (rc != 0) {
         xmlrpc_asprintf(errorP, "Unable to create a pipe to use to interrupt "
                         "waits.  pipe() failed with errno %d (%s)",
                         errno, strerror(errno));
-    else {
+       } else {
         *errorP = NULL;
         pipeP->interruptorFd = pipeFd[1];
         pipeP->interrupteeFd = pipeFd[0];
@@ -72,10 +72,14 @@ initInterruptPipe(interruptPipe * const pipeP,
 
 
 static void
-termInterruptPipe(interruptPipe const pipe) {
-
-    close(pipe.interruptorFd);
-    close(pipe.interrupteeFd);
+termInterruptPipe(interruptPipe pipe) {
+
+       if (pipe.interruptorFd) {
+               sane_close(pipe.interruptorFd);
+       }
+       if (pipe.interrupteeFd) {
+               sane_close(pipe.interrupteeFd);
+       }
 }
 
 
@@ -153,7 +157,7 @@ channelDestroy(TChannel * const channelP) {
     termInterruptPipe(socketUnixP->interruptPipe);
 
     if (!socketUnixP->userSuppliedFd)
-        close(socketUnixP->fd);
+        sane_close(socketUnixP->fd);
 
     free(socketUnixP);
 }
@@ -484,13 +488,13 @@ makeChannelFromFd(int           const fd,
     struct socketUnix * socketUnixP;
 
     MALLOCVAR(socketUnixP);
-    
+
     if (socketUnixP == NULL)
         xmlrpc_asprintf(errorP, "Unable to allocate memory for Unix "
                         "channel descriptor");
     else {
         TChannel * channelP;
-        
+
         socketUnixP->fd = fd;
         socketUnixP->userSuppliedFd = TRUE;
 
@@ -498,7 +502,6 @@ makeChannelFromFd(int           const fd,
 
         if (!*errorP) {
             ChannelCreate(&channelVtbl, socketUnixP, &channelP);
-        
             if (channelP == NULL)
                 xmlrpc_asprintf(errorP, "Unable to allocate memory for "
                                 "channel descriptor.");
@@ -564,7 +567,7 @@ chanSwitchDestroy(TChanSwitch * const chanSwitchP) {
     termInterruptPipe(socketUnixP->interruptPipe);
 
     if (!socketUnixP->userSuppliedFd)
-        close(socketUnixP->fd);
+        sane_close(socketUnixP->fd);
 
     free(socketUnixP);
 }
@@ -728,13 +731,13 @@ chanSwitchAccept(TChanSwitch * const chanSwitchP,
             rc = accept(listenSocketP->fd, &peerAddr, &size);
 
             if (rc >= 0) {
-                int const acceptedFd = rc;
+                int acceptedFd = rc;
 
                 createChannelForAccept(acceptedFd, peerAddr,
                                        &channelP, channelInfoPP, errorP);
 
                 if (*errorP)
-                    close(acceptedFd);
+                    sane_close(acceptedFd);
             } else if (errno == EINTR)
                 interrupted = TRUE;
             else
@@ -884,7 +887,7 @@ ChanSwitchUnixCreate(unsigned short const portNumber,
         xmlrpc_asprintf(errorP, "socket() failed with errno %d (%s)",
                         errno, strerror(errno));
     else {
-        int const socketFd = rc;
+        int socketFd = rc;
 
         setSocketOptions(socketFd, errorP);
         if (!*errorP) {
@@ -896,7 +899,7 @@ ChanSwitchUnixCreate(unsigned short const portNumber,
             }
         }
         if (*errorP)
-            close(socketFd);
+            sane_close(socketFd);
     }
 }