<?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>topic Bug Report: Critical memory leak in DSPI Master Peripheral Driver in combination with FreeRTOS in Kinetis Software Development Kit</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Bug-Report-Critical-memory-leak-in-DSPI-Master-Peripheral-Driver/m-p/374518#M822</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Affected function:&lt;/STRONG&gt;&lt;EM&gt; DSPI_DRV_MasterTransferDataBlocking(...)&lt;/EM&gt; in .&lt;EM&gt;/KSDK/platform/drivers/dspi/dspi_master/src/fsl_dspi_master_driver.c&lt;/EM&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Leak conditions:&lt;/STRONG&gt; utilize DSPI Peripheral Driver in combination with FreeRTOS (not verified for other RTOS implementations)&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Leak description:&lt;/STRONG&gt; for every call to &lt;EM&gt;DSPI_DRV_MasterTransferDataBlocking(...)&lt;/EM&gt; a new counting semaphore is created using a unconditional function call to&lt;EM&gt; OSA_SemaCreate(..).&lt;/EM&gt; This routes to the FreeRTOS function xSemaphoreCreateCounting(...) which will allocate new memory for the requested Semaphore using the local malloc implementation. The returned new memory address is assigned to the Semaphore Sync Object Pointer in the DSPI State Object (irqSync) without ever freeing the memory of the formerly created Semaphore hereby loosing any reference to the old memory. This will lead to a stack overflow after certain number of calls to the TransferData function depending on the stack size.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Workaround:&lt;/STRONG&gt; Check if the Semaphore has been created before calling &lt;EM&gt;OSA_SemaCreate(...)&lt;/EM&gt;. Instead loop over the Semaphore with a timeout of 0 trying to acquire it until its count is 0 to put it in the same condition as it would be after initialization.&lt;/P&gt;&lt;P&gt;(see &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fpastebin.com%2F1Xw5Gixw" rel="nofollow" target="_blank"&gt;[C] Memory Leak in KSDK DSPI Master Peripheral Driver Workaround - Pastebin.com&lt;/A&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Nov 2014 15:03:36 GMT</pubDate>
    <dc:creator>kora</dc:creator>
    <dc:date>2014-11-03T15:03:36Z</dc:date>
    <item>
      <title>Bug Report: Critical memory leak in DSPI Master Peripheral Driver in combination with FreeRTOS</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Bug-Report-Critical-memory-leak-in-DSPI-Master-Peripheral-Driver/m-p/374518#M822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Affected function:&lt;/STRONG&gt;&lt;EM&gt; DSPI_DRV_MasterTransferDataBlocking(...)&lt;/EM&gt; in .&lt;EM&gt;/KSDK/platform/drivers/dspi/dspi_master/src/fsl_dspi_master_driver.c&lt;/EM&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Leak conditions:&lt;/STRONG&gt; utilize DSPI Peripheral Driver in combination with FreeRTOS (not verified for other RTOS implementations)&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Leak description:&lt;/STRONG&gt; for every call to &lt;EM&gt;DSPI_DRV_MasterTransferDataBlocking(...)&lt;/EM&gt; a new counting semaphore is created using a unconditional function call to&lt;EM&gt; OSA_SemaCreate(..).&lt;/EM&gt; This routes to the FreeRTOS function xSemaphoreCreateCounting(...) which will allocate new memory for the requested Semaphore using the local malloc implementation. The returned new memory address is assigned to the Semaphore Sync Object Pointer in the DSPI State Object (irqSync) without ever freeing the memory of the formerly created Semaphore hereby loosing any reference to the old memory. This will lead to a stack overflow after certain number of calls to the TransferData function depending on the stack size.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Workaround:&lt;/STRONG&gt; Check if the Semaphore has been created before calling &lt;EM&gt;OSA_SemaCreate(...)&lt;/EM&gt;. Instead loop over the Semaphore with a timeout of 0 trying to acquire it until its count is 0 to put it in the same condition as it would be after initialization.&lt;/P&gt;&lt;P&gt;(see &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fpastebin.com%2F1Xw5Gixw" rel="nofollow" target="_blank"&gt;[C] Memory Leak in KSDK DSPI Master Peripheral Driver Workaround - Pastebin.com&lt;/A&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Nov 2014 15:03:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Bug-Report-Critical-memory-leak-in-DSPI-Master-Peripheral-Driver/m-p/374518#M822</guid>
      <dc:creator>kora</dc:creator>
      <dc:date>2014-11-03T15:03:36Z</dc:date>
    </item>
  </channel>
</rss>

