1
0

debug - find a memory leak

This commit is contained in:
Rémi Heredero 2024-04-21 21:23:15 +02:00
parent bbec23752f
commit 70a1dc41fa
3 changed files with 38 additions and 22 deletions

View File

@ -13,7 +13,10 @@ void send_DATA_IND(Adresse source, Adresse destination, uint8_t* dataFramePtr) {
queueMsg.addr = source.addr; queueMsg.addr = source.addr;
queueMsg.sapi = source.sapi; queueMsg.sapi = source.sapi;
strPtr = osMemoryPoolAlloc(memPool, osWaitForever); strPtr = osMemoryPoolAlloc(memPool, 0);
if(strPtr == NULL) {
assert(false);
}
for(uint8_t i = 0; i < dataFramePtr[2]; i++) { for(uint8_t i = 0; i < dataFramePtr[2]; i++) {
strPtr[i] = (char)dataFramePtr[3+i]; strPtr[i] = (char)dataFramePtr[3+i];
@ -27,7 +30,7 @@ void send_DATA_IND(Adresse source, Adresse destination, uint8_t* dataFramePtr) {
queue_timeR_id, queue_timeR_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
break; break;
case CHAT_SAPI: case CHAT_SAPI:
@ -35,7 +38,7 @@ void send_DATA_IND(Adresse source, Adresse destination, uint8_t* dataFramePtr) {
queue_chatR_id, queue_chatR_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
break; break;
default: default:
@ -57,7 +60,7 @@ void send_DATABACK(Adresse source, Adresse destination, uint8_t* dataFramePtr) {
queue_macS_id, queue_macS_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
} }
@ -102,6 +105,7 @@ void MacReceiver(void *argument) {
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); osWaitForever);
printf("Token received\r\n");
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
} else { } else {
@ -142,7 +146,7 @@ void MacReceiver(void *argument) {
queue_phyS_id, queue_phyS_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
} }
@ -166,7 +170,7 @@ void MacReceiver(void *argument) {
queue_phyS_id, queue_phyS_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
} }

View File

@ -1,4 +1,5 @@
#include "main.h" #include "main.h"
#include <cstdio>
#include <string.h> #include <string.h>
uint8_t* lastToken; uint8_t* lastToken;
@ -57,22 +58,18 @@ void MacSender(void *argument) {
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); osWaitForever);
printf("Token sended\r\n");
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
// Send one msg from internal queue if exist // Send one msg from internal queue if exist
if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue //if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue
retCode = osMessageQueueGet( if(osMessageQueueGet(queue_macData_id, &queueMsg, NULL, 0) == 0){
queue_macData_id,
&queueMsg,
NULL,
osWaitForever);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
queueMsg.type = TO_PHY; queueMsg.type = TO_PHY;
retCode = osMessageQueuePut( retCode = osMessageQueuePut(
queue_phyS_id, queue_phyS_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
} }
@ -83,7 +80,7 @@ void MacSender(void *argument) {
queue_phyS_id, queue_phyS_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
break; break;
} }
@ -97,19 +94,34 @@ void MacSender(void *argument) {
length = msg[2]; length = msg[2];
status.raw = msg[3+length]; status.raw = msg[3+length];
if(status.read == 0) { if(src.addr == BROADCAST_ADDRESS) {
retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
}
if(status.read == 1) {
if(status.ack == 0) { if(status.ack == 0) {
msg = osMemoryPoolAlloc(memPool, osWaitForever); msg = osMemoryPoolAlloc(memPool, osWaitForever);
queueMsg.type = TO_PHY; queueMsg.type = TO_PHY;
queueMsg.anyPtr = //queueMsg.anyPtr =
} else { } else {
} }
} else { } else {
// Send original message to PHY
queueMsg.type = TO_PHY;
retCode = osMessageQueuePut(
queue_macData_id,
&queueMsg,
osPriorityNormal,
0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
// Send error message to LCD
strPtr = osMemoryPoolAlloc(memPool, osWaitForever); strPtr = osMemoryPoolAlloc(memPool, osWaitForever);
sprintf(strPtr, "Dest. %d couldn't read message from %d\0", dst.add+1, src.addr+1); sprintf(strPtr, "Dest. %d couldn't read message from %d\0", dst.addr+1, src.addr+1);
queueMsg.type = MAC_ERROR; queueMsg.type = MAC_ERROR;
queueMsg.addr = src.addr; queueMsg.addr = src.addr;
queueMsg.sapi = src.sapi; queueMsg.sapi = src.sapi;
@ -118,7 +130,7 @@ void MacSender(void *argument) {
queue_lcd_id, queue_lcd_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
} }
break; break;
@ -184,7 +196,7 @@ void MacSender(void *argument) {
status.ack = 0; status.ack = 0;
} }
msg = osMemoryPoolAlloc(memPool, osWaitForever); msg = osMemoryPoolAlloc(memPool, osWaitForever); // TODO - Leak of memory
msg[0] = src.raw; msg[0] = src.raw;
msg[1] = dst.raw; msg[1] = dst.raw;
msg[2] = length; msg[2] = length;
@ -200,7 +212,7 @@ void MacSender(void *argument) {
queue_macData_id, queue_macData_id,
&queueMsg, &queueMsg,
osPriorityNormal, osPriorityNormal,
osWaitForever); 0);
CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE);
break; break;
} }

2
main.h
View File

@ -138,4 +138,4 @@ typedef union {
uint8_t checksum: 6; // LSB uint8_t checksum: 6; // LSB
}; };
uint8_t raw; uint8_t raw;
} Status; } Status;