Browse Source

Fixed Mismatched free() / delete / delete in utilizeBasicEvent function

pull/7/head
Evgeny Gagua 10 months ago
parent
commit
c0cc8b8d39
  1. 7
      lib/components/base/basicEvent.cpp
  2. 2
      lib/components/base/basicEvent.h
  3. 2
      lib/components/base/basicEventHeap.cpp
  4. 11
      lib/components/base/basicPosition.cpp
  5. 40
      lib/components/base/basicRing.h

7
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;

2
lib/components/base/basicEvent.h

@ -244,7 +244,7 @@ typedef struct S_SERVA_VIDEO_TRANSFER_INFO{
//typedef std::queue<CLIENT_EVENT*> 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 );

2
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);

11
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.

40
lib/components/base/basicRing.h

@ -12,7 +12,7 @@
*/
template <class T> class basicRing {
private:
basicMutex *m_pAccessMutex;
basicMutex m_pAccessMutex;
//basicRingElement<T> *cursor;
basicRingElement<T> *first;
basicRingElement<T> *last;
@ -55,12 +55,11 @@ template <class T> basicRing<T>::basicRing(){
count = 0;
first = NULL;
last = NULL;
m_pAccessMutex = new basicMutex();
};
template <class T> int basicRing<T>::push( T *ptr ){
int RetVal;
m_pAccessMutex->lock();
m_pAccessMutex.lock();
if ( last == NULL ){
//last = new basicRingElement<T>();
last = ( basicRingElement<T> *) malloc ( sizeof( basicRingElement<T> ) );
@ -69,7 +68,7 @@ template <class T> int basicRing<T>::push( T *ptr ){
last->prev = NULL;
last->next = NULL;
} else {
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return -1;
};
} else {
@ -79,7 +78,7 @@ template <class T> int basicRing<T>::push( T *ptr ){
last->next->prev = last;
last = last->next;
} else {
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return -1;
};
};
@ -87,13 +86,13 @@ template <class T> int basicRing<T>::push( T *ptr ){
RetVal = last->id = basicRingRing_ID_INTERATOR++;
last->next = NULL;
count++;
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return RetVal;
};
template <class T> int basicRing<T>::add(T* ptr) {
int RetVal;
m_pAccessMutex->lock();
m_pAccessMutex.lock();
if (first == NULL) {
first = (basicRingElement<T>*) malloc(sizeof(basicRingElement<T>));
if (first != NULL) {
@ -101,7 +100,7 @@ template <class T> int basicRing<T>::add(T* ptr) {
first->prev = NULL;
first->next = NULL;
} else {
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return -1;
};
} else {
@ -112,7 +111,7 @@ template <class T> int basicRing<T>::add(T* ptr) {
first->prev = tVal;
first = tVal;
} else {
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return -1;
};
};
@ -120,13 +119,13 @@ template <class T> int basicRing<T>::add(T* ptr) {
RetVal = first->id = basicRingRing_ID_INTERATOR++;
first->prev = NULL;
count++;
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return RetVal;
};
template <class T> void basicRing<T>::removePtr( T *ptr ){
basicRingElement<T> *temp;
m_pAccessMutex->lock();
m_pAccessMutex.lock();
temp = first;
while( temp != NULL ) {
if( temp->data == ptr ) break;
@ -148,13 +147,13 @@ template <class T> void basicRing<T>::removePtr( T *ptr ){
delete( temp );
count--;
};
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
};
template <class T> int basicRing<T>::removeAt( basicRingElement<T> *&cursor ){
basicRingElement<T> *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 <class T> int basicRing<T>::removeAt( basicRingElement<T> *&cursor ){
count = 0;
RetVal = 0;
}
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return RetVal;
};
template <class T> T *basicRing<T>::pop( void ){
basicRingElement<T> *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 <class T> T *basicRing<T>::pop( void ){
RetVal = NULL;
count = 0;
}
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
return RetVal;
};
/*
@ -250,16 +249,16 @@ template <class T> int basicRing<T>::removeNode(void){
};
*/
template <class T> T *basicRing<T>::fetch( U32 id ){
m_pAccessMutex->lock();
m_pAccessMutex.lock();
basicRingElement<T> *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 <class T> void basicRing<T>::getSequentalDown( void ){
template <class T> basicRing<T>::~basicRing(){
basicRingElement<T> *cursor;
cursor = begin();
m_pAccessMutex->unlock();
m_pAccessMutex.unlock();
while( removeAt( cursor ) );
delete( m_pAccessMutex );
};

Loading…
Cancel
Save