From c0cc8b8d3994fb58bfb0715d82e5ca4ad7e0a051 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Thu, 12 Feb 2026 18:06:42 +0200 Subject: [PATCH] Fixed Mismatched free() / delete / delete in utilizeBasicEvent function --- lib/components/base/basicEvent.cpp | 7 +++-- lib/components/base/basicEvent.h | 2 +- lib/components/base/basicEventHeap.cpp | 2 +- lib/components/base/basicPosition.cpp | 11 +++++++ lib/components/base/basicRing.h | 40 ++++++++++++-------------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/lib/components/base/basicEvent.cpp b/lib/components/base/basicEvent.cpp index c86a22cf..fbc6beea 100644 --- a/lib/components/base/basicEvent.cpp +++ b/lib/components/base/basicEvent.cpp @@ -55,13 +55,13 @@ void utilizeBasicEvent( EVENT_CONTAINER &Evt ){ Evt.m_eType = EVT_NOINIT; }; -void utilizeBasicEvent( EVENT_CONTAINER *Evt ){ +void utilizeBasicEvent( EVENT_CONTAINER *&Evt ){ if( Evt == NULL ) return; if( Evt->m_pHumanReadableMsg != NULL ) { delete( Evt->m_pHumanReadableMsg ); }; if( Evt->m_pEvtData != NULL ){ - switch (Evt->m_eType){ + switch( Evt->m_eType ){ case EVT_FH_MISSION_BEGIN: case EVT_FH_BUSY: case EVT_FH_CANCEL_ACTION: @@ -90,7 +90,8 @@ void utilizeBasicEvent( EVENT_CONTAINER *Evt ){ default: free(Evt->m_pEvtData); }; }; - delete( Evt ); + free( Evt ); + Evt = NULL; }; static uint32_t EventSeed_Counter = 0; diff --git a/lib/components/base/basicEvent.h b/lib/components/base/basicEvent.h index 68df5c21..2094582e 100644 --- a/lib/components/base/basicEvent.h +++ b/lib/components/base/basicEvent.h @@ -244,7 +244,7 @@ typedef struct S_SERVA_VIDEO_TRANSFER_INFO{ //typedef std::queue EventsFIFO; void utilizeBasicEvent( EVENT_CONTAINER &Evt ); -void utilizeBasicEvent( EVENT_CONTAINER *Evt ); +void utilizeBasicEvent( EVENT_CONTAINER *&Evt ); EVENT_CONTAINER *createBasicEvent( uint64_t SRC, basicEventClassID Class, basicEventTypeID Type, char *RefUUID = NULL, char *Msg = NULL, void *Data = NULL, uint32_t tss=0, uint16_t tms=0 ); EVENT_CONTAINER *createBasicTargetedEvent( uint64_t SRC, uint64_t DST, basicEventClassID Class, basicEventTypeID Type, char *RefUUID = NULL, char *Msg = NULL, void *Data = NULL, uint32_t tss=0, uint16_t tms=0 ); diff --git a/lib/components/base/basicEventHeap.cpp b/lib/components/base/basicEventHeap.cpp index 437f5c7e..90ca8646 100644 --- a/lib/components/base/basicEventHeap.cpp +++ b/lib/components/base/basicEventHeap.cpp @@ -46,7 +46,7 @@ void basicEventHeap::m_fThreadProc( void ){ m_vEventQueue.pop(); }; m_pDispatchingMutex->unlock(); - if( mpEvent!= NULL ){ + if( mpEvent != NULL ){ m_pHandlerMutex->lock(); for( V_EVT_HANDLER::iterator idx = m_vHandlers.begin(); idx< m_vHandlers.end();idx++) { mpHandler = (*idx); diff --git a/lib/components/base/basicPosition.cpp b/lib/components/base/basicPosition.cpp index 9c6de51b..83f80002 100644 --- a/lib/components/base/basicPosition.cpp +++ b/lib/components/base/basicPosition.cpp @@ -1,5 +1,6 @@ #include "basicPosition.h" #include "string.h" + position3D::position3D() { x = y = z = lat = lon = rot_z = rot_y = rot_z = speed = 0.f; utmZone = 0; @@ -144,6 +145,11 @@ void position3D::setOrientationDeg(C3D_FLOAT RotX, C3D_FLOAT RotY, C3D_FLOAT Rot void position3D::setSpeed(C3D_FLOAT Speed) { speed = Speed; }; + + + + + // Constructor implementation basicPosition::basicPosition(): position3D() { m_pTransform = NULL; @@ -192,6 +198,10 @@ basicPosition::basicPosition( float Lat, float Lon, float Alt, float h_lat, floa position3D::setSpeed( Speed ); updateMatrix(); }; + + + + void basicPosition::setPositionRad(float Lat, float Lon, float Alt, float h_lat, float h_lon, float h_alt, float Speed ){ position3D::setPositionWGS84(Lat, Lon, Alt); position3D::setOrientationRad(h_lat, h_lon, h_alt); @@ -204,6 +214,7 @@ void basicPosition::setPositionDeg(float Lat, float Lon, float Alt, float h_lat, position3D::setSpeed(Speed); updateMatrix(); }; + void basicPosition::updateMatrix( void ){ /** @todo Valgrind is showing several memory leaks from this function. diff --git a/lib/components/base/basicRing.h b/lib/components/base/basicRing.h index eb43c8d1..cdc152f1 100644 --- a/lib/components/base/basicRing.h +++ b/lib/components/base/basicRing.h @@ -12,7 +12,7 @@ */ template class basicRing { private: - basicMutex *m_pAccessMutex; + basicMutex m_pAccessMutex; //basicRingElement *cursor; basicRingElement *first; basicRingElement *last; @@ -55,12 +55,11 @@ template basicRing::basicRing(){ count = 0; first = NULL; last = NULL; - m_pAccessMutex = new basicMutex(); }; template int basicRing::push( T *ptr ){ int RetVal; - m_pAccessMutex->lock(); + m_pAccessMutex.lock(); if ( last == NULL ){ //last = new basicRingElement(); last = ( basicRingElement *) malloc ( sizeof( basicRingElement ) ); @@ -69,7 +68,7 @@ template int basicRing::push( T *ptr ){ last->prev = NULL; last->next = NULL; } else { - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return -1; }; } else { @@ -79,7 +78,7 @@ template int basicRing::push( T *ptr ){ last->next->prev = last; last = last->next; } else { - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return -1; }; }; @@ -87,13 +86,13 @@ template int basicRing::push( T *ptr ){ RetVal = last->id = basicRingRing_ID_INTERATOR++; last->next = NULL; count++; - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return RetVal; }; template int basicRing::add(T* ptr) { int RetVal; - m_pAccessMutex->lock(); + m_pAccessMutex.lock(); if (first == NULL) { first = (basicRingElement*) malloc(sizeof(basicRingElement)); if (first != NULL) { @@ -101,7 +100,7 @@ template int basicRing::add(T* ptr) { first->prev = NULL; first->next = NULL; } else { - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return -1; }; } else { @@ -112,7 +111,7 @@ template int basicRing::add(T* ptr) { first->prev = tVal; first = tVal; } else { - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return -1; }; }; @@ -120,13 +119,13 @@ template int basicRing::add(T* ptr) { RetVal = first->id = basicRingRing_ID_INTERATOR++; first->prev = NULL; count++; - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return RetVal; }; template void basicRing::removePtr( T *ptr ){ basicRingElement *temp; - m_pAccessMutex->lock(); + m_pAccessMutex.lock(); temp = first; while( temp != NULL ) { if( temp->data == ptr ) break; @@ -148,13 +147,13 @@ template void basicRing::removePtr( T *ptr ){ delete( temp ); count--; }; - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); }; template int basicRing::removeAt( basicRingElement *&cursor ){ basicRingElement *temp; int RetVal; - m_pAccessMutex->lock(); + m_pAccessMutex.lock(); if( cursor != NULL ){ //delete cursor->data; if ( cursor->prev != NULL && cursor->next != NULL ){ @@ -189,14 +188,14 @@ template int basicRing::removeAt( basicRingElement *&cursor ){ count = 0; RetVal = 0; } - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return RetVal; }; template T *basicRing::pop( void ){ basicRingElement *temp; T *RetVal; - m_pAccessMutex->lock(); + m_pAccessMutex.lock(); if( first != NULL ){ if (first == last) last = NULL; RetVal = first->data; @@ -208,7 +207,7 @@ template T *basicRing::pop( void ){ RetVal = NULL; count = 0; } - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return RetVal; }; /* @@ -250,16 +249,16 @@ template int basicRing::removeNode(void){ }; */ template T *basicRing::fetch( U32 id ){ - m_pAccessMutex->lock(); + m_pAccessMutex.lock(); basicRingElement *cursor = begin(); while ( cursor != NULL ){ if( cursor->id == id ) { - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return cursor->data; } cursor = cursor->next; }; - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); return NULL; }; @@ -285,9 +284,8 @@ template void basicRing::getSequentalDown( void ){ template basicRing::~basicRing(){ basicRingElement *cursor; cursor = begin(); - m_pAccessMutex->unlock(); + m_pAccessMutex.unlock(); while( removeAt( cursor ) ); - delete( m_pAccessMutex ); };