1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-22 18:25:57 +01:00

OfflinePacketFilter: avoid leaks on error in init

This commit is contained in:
Derrick Lyndon Pallas
2019-04-11 18:10:56 +00:00
parent 3385df9cc9
commit d74520768b

View File

@@ -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());
}
}