From e5d1acf76e41b1d54b26f100b2c7dc3eedb8f9a9 Mon Sep 17 00:00:00 2001 From: Levente Meszaros Date: Fri, 18 Oct 2024 14:39:21 +0200 Subject: [PATCH] 802.11: Fixed various memory leaks detected by sanitizer tests. --- .../ieee80211/mode/Ieee80211HtMode.cc | 5 +++++ .../ieee80211/mode/Ieee80211OfdmModulation.h | 2 ++ .../ieee80211/mode/Ieee80211VhtMode.cc | 22 +++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211HtMode.cc b/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211HtMode.cc index a2d9d561e61..f1840b18c76 100644 --- a/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211HtMode.cc +++ b/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211HtMode.cc @@ -357,11 +357,16 @@ const Ieee80211HtMode *Ieee80211HtCompliantModes::getCompliantMode(const Ieee802 Ieee80211Htmcs::~Ieee80211Htmcs() { delete code; + delete stream1Modulation; + delete stream2Modulation; + delete stream3Modulation; + delete stream4Modulation; } Ieee80211HtSignalMode::~Ieee80211HtSignalMode() { delete code; + delete modulation; } const DI Ieee80211HtmcsTable::htMcs0BW20MHz([](){ return new Ieee80211Htmcs(0, &BpskModulation::singleton, &Ieee80211OfdmCompliantCodes::ofdmConvolutionalCode1_2, MHz(20));}); diff --git a/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211OfdmModulation.h b/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211OfdmModulation.h index ce589927ceb..a1d85c8c925 100644 --- a/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211OfdmModulation.h +++ b/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211OfdmModulation.h @@ -22,6 +22,8 @@ class INET_API Ieee80211OfdmModulation : public IModulation public: Ieee80211OfdmModulation(int numSubcarriers, const ApskModulationBase *subcarrierModulation); + virtual cObject *dup() const override { return new Ieee80211OfdmModulation(numSubcarriers, subcarrierModulation); } + virtual int getNumSubcarriers() const { return numSubcarriers; } const ApskModulationBase *getSubcarrierModulation() const { return subcarrierModulation; } diff --git a/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211VhtMode.cc b/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211VhtMode.cc index f856ffdf0e2..30d69fe2e51 100644 --- a/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211VhtMode.cc +++ b/src/inet/physicallayer/wireless/ieee80211/mode/Ieee80211VhtMode.cc @@ -204,19 +204,19 @@ Ieee80211Vhtmcs::Ieee80211Vhtmcs(unsigned int mcsIndex, const ApskModulationBase bandwidth(bandwidth) { if (nss > 1) - stream2Modulation = stream1Modulation; + stream2Modulation = static_cast(stream1Modulation->dup()); if (nss > 2) - stream3Modulation = stream1Modulation; + stream3Modulation = static_cast(stream1Modulation->dup()); if (nss > 3) - stream4Modulation = stream1Modulation; + stream4Modulation = static_cast(stream1Modulation->dup()); if (nss > 4) - stream5Modulation = stream1Modulation; + stream5Modulation = static_cast(stream1Modulation->dup()); if (nss > 5) - stream6Modulation = stream1Modulation; + stream6Modulation = static_cast(stream1Modulation->dup()); if (nss > 6) - stream7Modulation = stream1Modulation; + stream7Modulation = static_cast(stream1Modulation->dup()); if (nss > 7) - stream8Modulation = stream1Modulation; + stream8Modulation = static_cast(stream1Modulation->dup()); code = Ieee80211VhtCompliantCodes::getCompliantCode(convolutionalCode, stream1Modulation, stream2Modulation, stream3Modulation, stream4Modulation, stream5Modulation, stream6Modulation, stream7Modulation, stream8Modulation, bandwidth); } @@ -702,6 +702,14 @@ const Ieee80211VhtMode *Ieee80211VhtCompliantModes::getCompliantMode(const Ieee8 Ieee80211Vhtmcs::~Ieee80211Vhtmcs() { delete code; + delete stream1Modulation; + delete stream2Modulation; + delete stream3Modulation; + delete stream4Modulation; + delete stream5Modulation; + delete stream6Modulation; + delete stream7Modulation; + delete stream8Modulation; } Ieee80211VhtSignalMode::~Ieee80211VhtSignalMode()