]> The Tcpdump Group git mirrors - libpcap/commitdiff
pcap_findalldevs_ex(): close directory handle before returning.
authorGuy Harris <[email protected]>
Tue, 12 Jul 2022 19:52:35 +0000 (12:52 -0700)
committerGuy Harris <[email protected]>
Thu, 14 Jul 2022 05:19:47 +0000 (22:19 -0700)
This should fix Coverity CID 1507240.

(cherry picked from commit 2d020a1a692c4b93d63fc15d041db89b0656fa75)

pcap-new.c

index 77b08ae1f090c300c18af990434c9eb3c7785f09..76388a998fd58a44545776cf8c3ed8848c184328 100644 (file)
@@ -241,6 +241,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
                        DIAG_OFF_FORMAT_TRUNCATION
                        snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path);
                        DIAG_ON_FORMAT_TRUNCATION
+                       closedir(unixdir);
                        return -1;
                }
 #endif
@@ -273,6 +274,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
                                            PCAP_ERRBUF_SIZE, errno,
                                            "malloc() failed");
                                        pcap_freealldevs(*alldevs);
+#ifdef _WIN32
+                                       FindClose(filehandle);
+#else
+                                       closedir(unixdir);
+#endif
                                        return -1;
                                }
 
@@ -302,6 +308,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
                                if (pcap_createsrcstr(tmpstring, PCAP_SRC_FILE, NULL, NULL, filename, errbuf) == -1)
                                {
                                        pcap_freealldevs(*alldevs);
+#ifdef _WIN32
+                                       FindClose(filehandle);
+#else
+                                       closedir(unixdir);
+#endif
                                        return -1;
                                }
 
@@ -312,6 +323,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
                                            PCAP_ERRBUF_SIZE, errno,
                                            "malloc() failed");
                                        pcap_freealldevs(*alldevs);
+#ifdef _WIN32
+                                       FindClose(filehandle);
+#else
+                                       closedir(unixdir);
+#endif
                                        return -1;
                                }
 
@@ -326,6 +342,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
                                            PCAP_ERRBUF_SIZE, errno,
                                            "malloc() failed");
                                        pcap_freealldevs(*alldevs);
+#ifdef _WIN32
+                                       FindClose(filehandle);
+#else
+                                       closedir(unixdir);
+#endif
                                        return -1;
                                }
 
@@ -339,9 +360,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
 #endif
 
 
-#ifdef _WIN32
                /* Close the search handle. */
+#ifdef _WIN32
                FindClose(filehandle);
+#else
+               closedir(unixdir);
 #endif
 
                return 0;