From d74520768b32c35eae422f2b9dda9a1bf494122d Mon Sep 17 00:00:00 2001 From: Derrick Lyndon Pallas Date: Thu, 11 Apr 2019 18:10:56 +0000 Subject: [PATCH] OfflinePacketFilter: avoid leaks on error in init --- src/offline_packet_filter.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/offline_packet_filter.cpp b/src/offline_packet_filter.cpp index a0fb462..ad8878a 100644 --- a/src/offline_packet_filter.cpp +++ b/src/offline_packet_filter.cpp @@ -58,8 +58,14 @@ void OfflinePacketFilter::init(const string& pcap_filter, link_type, snap_len ); + if (!handle_) { + throw pcap_open_failed(); + } if (pcap_compile(handle_, &filter_, pcap_filter.c_str(), 1, 0xffffffff) == -1) { - throw invalid_pcap_filter(pcap_geterr(handle_)); + string error(pcap_geterr(handle_)); + pcap_freecode(&filter_); + pcap_close(handle_); + throw invalid_pcap_filter(error.c_str()); } }