diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index 2e09e71f..0ec5ed5c 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -16,7 +16,11 @@ CcsdsDistributor::CcsdsDistributor(uint16_t setDefaultApid, object_id_t setObjec tcStore(tcStore), packetChecker(packetChecker) {} -CcsdsDistributor::~CcsdsDistributor() = default; +CcsdsDistributor::~CcsdsDistributor() { + if (ownedPacketChecker) { + delete packetChecker; + } +} ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { #if CCSDS_DISTRIBUTOR_DEBUGGING == 1 @@ -123,13 +127,14 @@ ReturnValue_t CcsdsDistributor::registerApplication(DestInfo info) { uint32_t CcsdsDistributor::getIdentifier() const { return 0; } ReturnValue_t CcsdsDistributor::initialize() { - if (packetChecker == nullptr) { - packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); - } ReturnValue_t result = TcDistributorBase::initialize(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } + if (packetChecker == nullptr) { + ownedPacketChecker = true; + packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); + } if (tcStore == nullptr) { tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (tcStore == nullptr) { diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h index 0444a868..83199646 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -78,6 +78,7 @@ class CcsdsDistributor : public TcDistributorBase, */ StorageManagerIF* tcStore = nullptr; + bool ownedPacketChecker = false; CcsdsPacketCheckIF* packetChecker = nullptr; };