<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MQX Software Solutions中的主题 Re: Solution for memory leaks in MQX 4.1’s PPP_init() and PPP_release()</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481656#M15786</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Joseph&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for looking at this, however, as I stated,&amp;nbsp; PPP_init() and PPP_release() are being called by the same task. I do not know why _mem_free() thinks it isn't.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also I do call PPP_memfree(ppp_ptr-&amp;gt;DEVICE_NAME) before calling PPP_memfree(handle). I will add the "if (ppp_ptr-&amp;gt;DEVICE_NAME)" check though, thanks :smileyhappy:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Feb 2016 09:43:44 GMT</pubDate>
    <dc:creator>Gra67</dc:creator>
    <dc:date>2016-02-24T09:43:44Z</dc:date>
    <item>
      <title>Solution for memory leaks in MQX 4.1’s PPP_init() and PPP_release()</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481654#M15784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;Note this also occurs in MQX 4.2.0.1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be grateful if a freescale member could validate the fixes I’ve applied to the rtcs files below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using break points I tracked the memory leak down to the PPP_init() PPP_release() functions.&lt;/P&gt;&lt;P&gt;The following list is the difference in the memory blocks between having never called PPP_init() and calling PPP_init() &amp;amp; PPP_release() twice:&lt;/P&gt;&lt;P&gt;0x20008d50&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x260&amp;nbsp;&amp;nbsp;&amp;nbsp; 608&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10013&lt;/P&gt;&lt;P&gt;0x20008fd0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10013&lt;/P&gt;&lt;P&gt;0x20009000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10013&lt;/P&gt;&lt;P&gt;0x20009040&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0xd0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 208&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10013&lt;/P&gt;&lt;P&gt;0x20009130&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x260&amp;nbsp;&amp;nbsp;&amp;nbsp; 608&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10013&lt;/P&gt;&lt;P&gt;0x200093f0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0xd0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 208&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10013&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="nxp1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/53873i538FED5FF7B26EC6/image-size/large?v=v2&amp;amp;px=999" role="button" title="nxp1.png" alt="nxp1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="nxp2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/53917i4C1DE61C99E64962/image-size/large?v=v2&amp;amp;px=999" role="button" title="nxp2.png" alt="nxp2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;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().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Solution&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;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().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code changes:&lt;/P&gt;&lt;P&gt;In “Freescale_MQX_4_1\rtcs\source\include\ppphdlc.h” I changed:&lt;/P&gt;&lt;P&gt;#define PPPHDLC_memalloc _mem_alloc_zero&lt;/P&gt;&lt;P&gt;to be&lt;/P&gt;&lt;P&gt;#define PPPHDLC_memalloc _mem_alloc_system_zero&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In “\Freescale_MQX_4_1\rtcs\source\ppp\ppp.c” function PPP_init() I changed:&lt;/P&gt;&lt;P&gt;ppp_ptr = _mem_alloc_zero(sizeof(PPP_CFG));&lt;/P&gt;&lt;P&gt;to be&lt;/P&gt;&lt;P&gt;ppp_ptr = _mem_alloc_system_zero(sizeof(PPP_CFG));&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;ppp_ptr-&amp;gt;DEVICE_NAME = _mem_alloc_zero(strlen(params-&amp;gt;device)+1);&lt;/P&gt;&lt;P&gt;to be&lt;/P&gt;&lt;P&gt;ppp_ptr-&amp;gt;DEVICE_NAME = _mem_alloc_system_zero(strlen(params-&amp;gt;device)+1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In “\Freescale_MQX_4_1\rtcs\source\ppp\ppp.c” function PPP_release() I added the following line just before “PPP_memfree(handle);”:&lt;/P&gt;&lt;P&gt;PPP_memfree(ppp_ptr-&amp;gt;DEVICE_NAME);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These changes cured the memory leaks, but is changing private memory to system memory ok?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 17:12:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481654#M15784</guid>
      <dc:creator>Gra67</dc:creator>
      <dc:date>2016-02-23T17:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Solution for memory leaks in MQX 4.1’s PPP_init() and PPP_release()</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481655#M15785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Graeme,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I have looked through the code. I think the problem occurs only when PPP_init() and PPP_release() are called by different tasks since private memory can only be freed by its owner. I would suggest to control PPP by one specific task. However, it's also fine if they are done by different tasks and using system memory allocation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Regarding the memory leak of ppp_ptr-&amp;gt;DEVICE_NAME, it should be freed before freeing the PPP handle. The code below should be added:&lt;/P&gt;&lt;P&gt;if (ppp_ptr-&amp;gt;DEVICE_NAME) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _mem_free(ppp_ptr-&amp;gt;DEVICE_NAME);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 02:04:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481655#M15785</guid>
      <dc:creator>josephchen</dc:creator>
      <dc:date>2016-02-24T02:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Solution for memory leaks in MQX 4.1’s PPP_init() and PPP_release()</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481656#M15786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Joseph&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for looking at this, however, as I stated,&amp;nbsp; PPP_init() and PPP_release() are being called by the same task. I do not know why _mem_free() thinks it isn't.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also I do call PPP_memfree(ppp_ptr-&amp;gt;DEVICE_NAME) before calling PPP_memfree(handle). I will add the "if (ppp_ptr-&amp;gt;DEVICE_NAME)" check though, thanks :smileyhappy:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 09:43:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481656#M15786</guid>
      <dc:creator>Gra67</dc:creator>
      <dc:date>2016-02-24T09:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Solution for memory leaks in MQX 4.1’s PPP_init() and PPP_release()</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481657#M15787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Graeme,&lt;/P&gt;&lt;P&gt;FYI - I reported this to the MQX Development team to look into as well.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 17:53:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Solution-for-memory-leaks-in-MQX-4-1-s-PPP-init-and-PPP-release/m-p/481657#M15787</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2016-02-24T17:53:53Z</dc:date>
    </item>
  </channel>
</rss>

