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

Merge pull request #343 from pallas/fix-several-leaks

Fix several leaks
This commit is contained in:
Matias Fontanini
2019-04-12 07:35:01 -07:00
committed by GitHub
2 changed files with 13 additions and 3 deletions

View File

@@ -37,11 +37,14 @@ using std::string;
namespace Tins {
OfflinePacketFilter::OfflinePacketFilter(const OfflinePacketFilter& other) {
*this = other;
string_filter_ = other.string_filter_;
init(string_filter_, pcap_datalink(other.handle_), pcap_snapshot(other.handle_));
}
OfflinePacketFilter& OfflinePacketFilter::operator=(const OfflinePacketFilter& other) {
string_filter_ = other.string_filter_;
pcap_freecode(&filter_);
pcap_close(handle_);
init(string_filter_, pcap_datalink(other.handle_), pcap_snapshot(other.handle_));
return* this;
}
@@ -58,8 +61,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());
}
}

View File

@@ -86,8 +86,9 @@ void PacketWriter::init(const string& file_name, int link_type) {
}
dumper_ = pcap_dump_open(handle_, file_name.c_str());
if (!dumper_) {
string error(pcap_geterr(handle_));
pcap_close(handle_);
throw pcap_error(pcap_geterr(handle_));
throw pcap_error(error);
}
}