From cd46a74cf49299d92640bfe63b4caf66e0cce65c Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 4 May 2015 10:55:35 -0700 Subject: Use pcap_close() if pcap_create_handle() fails. 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-linux.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'pcap-linux.c') diff --git a/pcap-linux.c b/pcap-linux.c index a226da12..bb4619bb 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -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; -- cgit v1.2.3