Note this also occurs in MQX 184.108.40.206
I would be grateful if a freescale member could validate the fixes I’ve applied to the rtcs files below.
Our product uses a GPRS modem to send UDP data. When the modem sends us a disconnect we close the connection to the modem and then attempt to re-connect again. Every time the IP connection to the modem was established the software grabbed another 944B. The spare RAM we had could quickly disappear it eventually lost GPRS connectivity.
I turned on kernel logging and found 2 memory free calls that failed due to MQX_NOT_RESOURCE_OWNER in the task that makes the PPP connection.
Using break points I tracked the memory leak down to the PPP_init() PPP_release() functions.
The following list is the difference in the memory blocks between having never called PPP_init() and calling PPP_init() & PPP_release() twice:
0x20008d50 0x260 608 0x10013
0x20008fd0 0x10 16 0x10013
0x20009000 0x20 32 0x10013
0x20009040 0xd0 208 0x10013
0x20009130 0x260 608 0x10013
0x200093f0 0xd0 208 0x10013
Stepping through the PPP_release() function I tracked the MQX_NOT_RESOURCE_OWNER errors down to the following calls (note that the call stack shows a different build to the Memory Block Summary shown above):
The above two blocks that couldn’t be freed (twice) are the 208B and 608B blocks. The _mem_free() reckons that the ModemDialupTask (0x10013) doesn’t own the blocks, but the Memory Block Summary clearly states they are owned by 0x10013 and it is currently in that same task!
The 16B and 30B blocks left are simply due to the fact the PPP_release didn’t free up a pointer that was allocated memory in PPP_init().
I could not work out why the _mem_free() kept failing with MQX_NOT_RESOURCE_OWNER as the current task did own the memory block, so I simply forced the memory allocation functions to use system memory instead and added the missing memory free in function PPP_release().
In “Freescale_MQX_4_1\rtcs\source\include\ppphdlc.h” I changed:
#define PPPHDLC_memalloc _mem_alloc_zero
#define PPPHDLC_memalloc _mem_alloc_system_zero
In “\Freescale_MQX_4_1\rtcs\source\ppp\ppp.c” function PPP_init() I changed:
ppp_ptr = _mem_alloc_zero(sizeof(PPP_CFG));
ppp_ptr = _mem_alloc_system_zero(sizeof(PPP_CFG));
ppp_ptr->DEVICE_NAME = _mem_alloc_zero(strlen(params->device)+1);
ppp_ptr->DEVICE_NAME = _mem_alloc_system_zero(strlen(params->device)+1);
In “\Freescale_MQX_4_1\rtcs\source\ppp\ppp.c” function PPP_release() I added the following line just before “PPP_memfree(handle);”:
These changes cured the memory leaks, but is changing private memory to system memory ok?