From 4f10a41ec0475bfaac0aab1ab2ad85dc11851625 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Mon, 22 Apr 2024 13:51:45 +0200 Subject: [PATCH] fix memory leak of mac sender --- mac_sender.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mac_sender.c b/mac_sender.c index 5824d8d..7afc154 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -1,6 +1,8 @@ #include "main.h" #include +#include #include +#include uint8_t* lastToken; osMessageQueueId_t queue_macData_id; @@ -94,12 +96,10 @@ void MacSender(void *argument) { length = msg[2]; status.raw = msg[3+length]; - if(src.addr == BROADCAST_ADDRESS) { + if(dst.addr == BROADCAST_ADDRESS) { retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); - } - - if(status.read == 1) { + } else if(status.read == 1) { if(status.ack == 0) { msg = osMemoryPoolAlloc(memPool, osWaitForever); queueMsg.type = TO_PHY; @@ -133,6 +133,8 @@ void MacSender(void *argument) { 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } + } + break; } @@ -196,7 +198,11 @@ void MacSender(void *argument) { status.ack = 0; } - msg = osMemoryPoolAlloc(memPool, osWaitForever); // TODO - Leak of memory + msg = osMemoryPoolAlloc(memPool, 0); // TODO - Leak of memory + if(msg == NULL) { + printf("Memory allocation failed\r\n"); + assert(false); + } msg[0] = src.raw; msg[1] = dst.raw; msg[2] = length;