]> The Tcpdump Group git mirrors - libpcap/commitdiff
Use pcap_close() if pcap_create_handle() fails.
authorGuy Harris <[email protected]>
Mon, 4 May 2015 17:55:35 +0000 (10:55 -0700)
committerGuy Harris <[email protected]>
Mon, 4 May 2015 17:55:35 +0000 (10:55 -0700)
Use it to free up all memory attached to the pcap_t, as well as the
pcap_t itself; that closes some memory leaks.

Fixes GitHub issue #432.

pcap-dag.c
pcap-linux.c
pcap-snf.c

index 491524893e7af9881dbcf0367364c52f48a4fce7..a363c4ccefefd656c7bfc5e969fbf2dae3049173 100644 (file)
@@ -950,9 +950,7 @@ pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
        if (p->tstamp_precision_list == NULL) {
                snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
                    pcap_strerror(errno));
-               if (p->tstamp_type_list != NULL)
-                       free(p->tstamp_type_list);
-               free(p);
+               pcap_close(p);
                return NULL;
        }
        p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
index a226da12e43937592a72ea69d9eaa0db78f38b71..bb4619bbb5f1584599bccbc7ea304b1980a33909 100644 (file)
@@ -459,7 +459,7 @@ pcap_create_interface(const char *device, char *ebuf)
         * See what time stamp types we support.
         */
        if (iface_ethtool_get_ts_info(handle, ebuf) == -1) {
-               free(handle);
+               pcap_close(handle);
                return NULL;
        }
 #endif
@@ -478,9 +478,7 @@ pcap_create_interface(const char *device, char *ebuf)
        if (handle->tstamp_precision_list == NULL) {
                snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
                    pcap_strerror(errno));
-               if (handle->tstamp_type_list != NULL)
-                       free(handle->tstamp_type_list);
-               free(handle);
+               pcap_close(handle);
                return NULL;
        }
        handle->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
index 03dc08def54b3468bd05f590c42eafb0cc940a81..bfa0990e0f6ddfe4fa378811381a076b32cd999a 100644 (file)
@@ -483,9 +483,7 @@ snf_create(const char *device, char *ebuf, int *is_ours)
        if (p->tstamp_precision_list == NULL) {
                snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
                    pcap_strerror(errno));
-               if (p->tstamp_type_list != NULL)
-                       free(p->tstamp_type_list);
-               free(p);
+               pcap_close(p);
                return NULL;
        }
        p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;