Skip to content

Commit 80d7158

Browse files
authored
Fixed memmanager and add assertion (#277)
* Fixed memmanager and add assertion assertion added for functions which are returning status on freeing memory Signed-off-by: Cervenka Dusan <cervenka@acrios.com> * Added NULL for free function Nullptr can be inserted if allocation failed. Expected state. Signed-off-by: Cervenka Dusan <cervenka@acrios.com> * Keep backward compatibility with older version of driver. Signed-off-by: Cervenka Dusan <cervenka@acrios.com> * Changes based on PR. Signed-off-by: Cervenka Dusan <cervenka@acrios.com>
1 parent 3abb86d commit 80d7158

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

erpc_c/port/erpc_config_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
#endif
197197

198198
#if !defined(erpc_assert)
199-
#if ERPC_HAS_FREERTOSCONFIG_H
199+
#if ERPC_HAS_FREERTOSCONFIG_H
200200
#ifdef __cplusplus
201201
extern "C" {
202202
#endif

erpc_c/port/erpc_port_memmanager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
extern "C" {
1515
#include "FreeRTOS.h"
16-
#include "MemManager.h"
16+
#include "fsl_component_mem_manager.h"
1717
}
1818

1919
#if !(__embedded_cplusplus)
@@ -58,13 +58,16 @@ void operator delete[](void *ptr) THROW
5858

5959
void *erpc_malloc(size_t size)
6060
{
61-
void *p = MEM_BufferAllocForever(size, 0);
61+
void *p = MEM_BufferAlloc(size);
6262
return p;
6363
}
6464

6565
void erpc_free(void *ptr)
6666
{
67-
MEM_BufferFree(ptr);
67+
if (ptr != NULL)
68+
{
69+
erpc_assert(MEM_BufferFree(ptr) == kStatus_MemSuccess);
70+
}
6871
}
6972

7073
/* Provide function for pure virtual call to avoid huge demangling code being linked in ARM GCC */

erpc_c/port/erpc_port_mqx.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ void *erpc_malloc(size_t size)
6262

6363
void erpc_free(void *ptr)
6464
{
65-
_mem_free(ptr);
65+
if (ptr != NULL)
66+
{
67+
erpc_assert(_mem_free(ptr) == MQX_OK);
68+
}
6669
}
6770

6871
/* Provide function for pure virtual call to avoid huge demangling code being linked in ARM GCC */

0 commit comments

Comments
 (0)