fix memory leak in main messages

This commit is contained in:
andreas 2021-10-30 13:49:20 +02:00
parent 9b65ce51d4
commit 11c6c78ad6
3 changed files with 16 additions and 10 deletions

View File

@ -245,9 +245,7 @@ bool SetAISClassBMessage24(tNMEA0183AISMsg &NMEA0183AISMsg, uint8_t MessageID,
uint8_t i; uint8_t i;
for ( i = 0; i < vships.size(); i++) { for ( i = 0; i < vships.size(); i++) {
if ( vships[i]->_userID == UserID ) { if ( vships[i]->_userID == UserID ) {
Serial.print("UserID gefunden: "); Serial.print(UserID);
ShipName = const_cast<char*>( vships[i]->_shipName.c_str() ); ShipName = const_cast<char*>( vships[i]->_shipName.c_str() );
Serial.print(" / "); Serial.println( ShipName);
} }
} }
if ( i > MAX_SHIP_IN_VECTOR ) { if ( i > MAX_SHIP_IN_VECTOR ) {

View File

@ -29,6 +29,8 @@ class Message{
} }
virtual ~Message(){ virtual ~Message(){
GW_MESSAGE_DEBUG("~Message %p\n",this); GW_MESSAGE_DEBUG("~Message %p\n",this);
vSemaphoreDelete(locker);
vSemaphoreDelete(notifier);
} }
void unref(){ void unref(){
GW_MESSAGE_DEBUG("Message::unref %p\n",this); GW_MESSAGE_DEBUG("Message::unref %p\n",this);
@ -81,9 +83,9 @@ class RequestMessage : public Message{
protected: protected:
virtual void processRequest()=0; virtual void processRequest()=0;
virtual void processImpl(){ virtual void processImpl(){
GW_MESSAGE_DEBUG("RequestMessage processImpl(1)"); GW_MESSAGE_DEBUG("RequestMessage processImpl(1) %p\n",this);
processRequest(); processRequest();
GW_MESSAGE_DEBUG("RequestMessage processImpl(2)"); GW_MESSAGE_DEBUG("RequestMessage processImpl(2) %p\n",this);
len=strlen(result.c_str()); len=strlen(result.c_str());
consumed=0; consumed=0;
handled=true; handled=true;
@ -92,6 +94,7 @@ class RequestMessage : public Message{
RequestMessage():Message(){ RequestMessage():Message(){
} }
virtual ~RequestMessage(){ virtual ~RequestMessage(){
GW_MESSAGE_DEBUG("~RequestMessage %p\n",this)
} }
String getResult(){return result;} String getResult(){return result;}
int getLen(){return len;} int getLen(){return len;}

View File

@ -12,7 +12,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define VERSION "0.1.2" #define VERSION "0.2.0"
//#define GW_MESSAGE_DEBUG_ENABLED
//#define FALLBACK_SERIAL
const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting
#include "GwHardware.h" #include "GwHardware.h"
#include <Arduino.h> #include <Arduino.h>
@ -223,8 +226,11 @@ void setup() {
if (usbBaud){ if (usbBaud){
baud=usbBaud->asInt(); baud=usbBaud->asInt();
} }
#ifdef FALLBACK_SERIAL
int st=-1;
#else
int st=usbSerial.setup(baud,3,1); //TODO: PIN defines int st=usbSerial.setup(baud,3,1); //TODO: PIN defines
//int st=-1; #endif
if (st < 0){ if (st < 0){
//falling back to old style serial for logging //falling back to old style serial for logging
Serial.begin(baud); Serial.begin(baud);
@ -497,11 +503,10 @@ class NMEAMessageReceiver : public GwBufferWriter{
}; };
NMEAMessageReceiver receiver; NMEAMessageReceiver receiver;
unsigned long lastHeapReport=0; unsigned long lastHeapReport=0;
const unsigned long HEAP_REPORT_TIME=2000;
void loop() { void loop() {
gwWifi.loop(); gwWifi.loop();
unsigned long now=millis(); unsigned long now=millis();
if (now > (lastHeapReport+HEAP_REPORT_TIME)){ if (HEAP_REPORT_TIME > 0 && now > (lastHeapReport+HEAP_REPORT_TIME)){
lastHeapReport=now; lastHeapReport=now;
if (logger.isActive(GwLog::DEBUG)){ if (logger.isActive(GwLog::DEBUG)){
logger.logDebug(GwLog::DEBUG,"Heap free=%ld, minFree=%ld", logger.logDebug(GwLog::DEBUG,"Heap free=%ld, minFree=%ld",
@ -526,7 +531,7 @@ void loop() {
//handle messages from the async web server //handle messages from the async web server
Message *msg=NULL; Message *msg=NULL;
if (xQueueReceive(queue,&msg,0)){ if (xQueueReceive(queue,&msg,0)){
logger.logDebug(GwLog::DEBUG,"main message"); logger.logDebug(GwLog::DEBUG+1,"main message");
msg->process(); msg->process();
msg->unref(); msg->unref();
} }