From 414e55fafccb329306fa28e54dd7dc7ca0710787 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 7 Jun 2019 22:14:24 +0200 Subject: [PATCH] pcap: add dtor this fixes issue if object is destroyed and PCAP is still open --- lib/include/srslte/common/mac_pcap.h | 3 ++- lib/src/common/mac_pcap.cc | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/include/srslte/common/mac_pcap.h b/lib/include/srslte/common/mac_pcap.h index 65a327c5b..fa6e5a967 100644 --- a/lib/include/srslte/common/mac_pcap.h +++ b/lib/include/srslte/common/mac_pcap.h @@ -30,7 +30,8 @@ namespace srslte { class mac_pcap { public: - mac_pcap() {enable_write=false; ue_id=0; pcap_file = NULL; }; + mac_pcap(); + ~mac_pcap(); void enable(bool en); void open(const char *filename, uint32_t ue_id = 0); void close(); diff --git a/lib/src/common/mac_pcap.cc b/lib/src/common/mac_pcap.cc index eb60b4146..1c4919544 100644 --- a/lib/src/common/mac_pcap.cc +++ b/lib/src/common/mac_pcap.cc @@ -25,7 +25,14 @@ #include "srslte/common/mac_pcap.h" namespace srslte { - + +mac_pcap::mac_pcap() : enable_write(false), ue_id(0), pcap_file(nullptr) {} + +mac_pcap::~mac_pcap() +{ + close(); +} + void mac_pcap::enable(bool en) { enable_write = true; @@ -39,8 +46,11 @@ void mac_pcap::open(const char* filename, uint32_t ue_id) void mac_pcap::close() { enable_write = false; - fprintf(stdout, "Saving MAC PCAP file\n"); - LTE_PCAP_Close(pcap_file); + if (pcap_file != nullptr) { + fprintf(stdout, "Saving MAC PCAP file\n"); + LTE_PCAP_Close(pcap_file); + pcap_file = nullptr; + } } void mac_pcap::set_ue_id(uint16_t ue_id) {