]> The Tcpdump Group git mirrors - libpcap/commitdiff
Free the socket temporary when appropriate.
authorGuy Harris <[email protected]>
Sun, 21 Jan 2018 18:21:18 +0000 (10:21 -0800)
committerGuy Harris <[email protected]>
Sun, 21 Jan 2018 18:21:18 +0000 (10:21 -0800)
If we're using threads, free it if the attempt to create the thread
fails.

If we're using subprocesses, free it in the parent process, which isn't
using it.

(We don't really teed the socket temporary if we're using subprocesses,
as the socket value won't be overwritten - the multiple socket opens are
done in separate processes.)

This should fix Coverity CID 1418994.

rpcapd/rpcapd.c

index cb5d4a0c5b22f0be18df75c6ccb178f7d48c732b..6699aa0f300c24274a8fe22ddf8f037672b50390 100755 (executable)
@@ -388,9 +388,23 @@ void main_startup(void)
                                continue;
                        }
 
-                       // This trick is needed in order to allow the child thread to save the 'sockmain' variable
-                       // withouth getting it overwritten by the sock_open, in case we want to open more than one waiting sockets
-                       // For instance, the rpcapd_thread_create() will accept the socktemp variable, and it will deallocate immediately that variable
+                       //
+                       // This trick is needed in order to allow the child
+                       // thread to save the 'sockmain' variable without
+                       // getting it overwritten by the sock_open, in case
+                       // we want to open more than one waiting socket.
+                       //
+                       // For instance, the rpcapd_thread_create() will
+                       // accept the socktemp variable, and it will
+                       // immediately deallocate that variable.
+                       //
+                       // XXX - this shouldn't be necessary if we're
+                       // using subprocesses rather than threads, as
+                       // the use and overwrite would be done in
+                       // separate processes; we should be able to
+                       // pass a pointer to sockmain in the child
+                       // process.
+                       //
                        socktemp = (SOCKET *) malloc (sizeof (SOCKET));
                        if (socktemp == NULL)
                                exit(0);
@@ -403,6 +417,7 @@ void main_startup(void)
                        if (threadId == 0)
                        {
                                SOCK_ASSERT("Error creating the passive child thread", 1);
+                               free(socktemp);
                                continue;
                        }
                        CloseHandle(threadId);
@@ -413,6 +428,7 @@ void main_startup(void)
                                main_passive((void *) socktemp);
                                return;
                        }
+                       free(socktemp);
 #endif
                        tempaddrinfo = tempaddrinfo->ai_next;
                }