<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59577/malloc-causing-fault-in-softdevice</link><description>I&amp;#39;m using s140 on an nRF52840 and running into a hard fault when trying to malloc 20 bytes. (Yes, I know about memory fragmentation; it&amp;#39;s not a concern here.) 
 app_error_fault_handler give me a counter of 0x1505C and a fault ID of 1 (and info of 0).</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 14 Mar 2023 13:08:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59577/malloc-causing-fault-in-softdevice" /><item><title>RE: malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/thread/415220?ContentTypeID=1</link><pubDate>Tue, 14 Mar 2023 13:08:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ba7344d-c96a-485a-8837-d25d464da28a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Looks like you have ended up in the error handler, which would typically happen if a function returns an error. Please create a new ticket where you describe your problem and we will help you resolve it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/thread/414176?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 14:41:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91fe81e9-03e1-4aa2-b709-e0c7991a39c4</guid><dc:creator>Sebastien DRI</dc:creator><description>&lt;p&gt;Hi Folks,&lt;/p&gt;
&lt;p&gt;Any fix concerning this issue cause we are facing the same problem randomly at the same address offset (See Screeshot below).&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1678286198916v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see, it is located at&amp;nbsp;&lt;span&gt;0x1505C and a fault ID of 1 (and info of 0) and the instruction refers to a call to &amp;quot;svc 255&amp;quot; (supervisor call&amp;nbsp; but unknow id).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;I use SDK 16.0.0 with softdevice 7.0.1&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I must add that this error occurs randomly in our functionning more precisely when uploading data to the target (which is a peripheral configured in long range mode) from a central so communication is stressed a bit.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/thread/242203?ContentTypeID=1</link><pubDate>Sat, 28 Mar 2020 10:18:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3fd85b4-e493-490c-a49e-5640058b7690</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;I figured out the root cause of these hard faults, but I&amp;#39;m at a loss to explain why they were causing an assertion error in the softdevice.&lt;/p&gt;
&lt;p&gt;My application takes variable length commands via usb serial and parses (application-level) headers before reading more data based on the headers.&amp;nbsp;There&amp;#39;s a state variable that keeps track of what&amp;#39;s been parsed and I had missed a state transition. This lead to payload data shifted further into the input buffer by the length of a header. This wouldn&amp;#39;t cause any overflow, because the input buffer is much larger than these particular messages.&lt;/p&gt;
&lt;p&gt;The part that perplexes me is that nothing was interacting with that corrupt data, aside from copying it to a temporary buffer, and then writing it to flash. In the struct for that data, the values are just numbers. If they were being used as a pointer, I could see how that could lead to errors by trying to access unavailable memory, but that wasn&amp;#39;t the case here.&lt;/p&gt;
&lt;p&gt;The only other thing I can think of is data languishing in the CDC ACM internal &amp;#39;in&amp;#39; buffer, but all of this code was ultimately being called from the same `cdc_acm_user_evt_handler`.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/thread/242198?ContentTypeID=1</link><pubDate>Sat, 28 Mar 2020 01:58:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:727c6d57-7948-497d-a078-24adccc6b645</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;And I spoke too soon, because the issue is back, but only the 2nd time the function is called via that particular code path. The same function is called via a different code path (during init) repeatedly without issue.&lt;/p&gt;
&lt;p&gt;Also, the error consistently occurs on this codepath if I&amp;#39;m stepping through w/ a debugger.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/thread/242195?ContentTypeID=1</link><pubDate>Sat, 28 Mar 2020 01:07:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5ec2a72-1f8d-462a-a21a-d96302559c4a</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;Some unrelated bug-fixing has caused this problem to miraculously fix itself.&lt;/p&gt;
&lt;p&gt;Our best guess is the softdevice somehow got corrupted and various subsequent wipes &amp;amp; re-flashes solved the issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/thread/242187?ContentTypeID=1</link><pubDate>Fri, 27 Mar 2020 21:15:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16ac83a4-df8d-4699-a1a2-73e06cfbb782</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;I&amp;#39;m using the SDK v16 with the s140. I&amp;#39;m very loosely basing this on the flash_fds example.&lt;/p&gt;
&lt;p&gt;My code is building an in-memory index of what&amp;#39;s being stored via FDS. The actual call is:&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;pattern_index_t &lt;/span&gt;&lt;span&gt;volatile &lt;/span&gt;*node = malloc(&lt;span&gt;sizeof&lt;/span&gt;(&lt;span&gt;pattern_index_t&lt;/span&gt;))&lt;span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;where&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;typedef volatile struct &lt;/span&gt;&lt;span&gt;pattern_index_t &lt;/span&gt;{&lt;br /&gt;    &lt;span&gt;struct &lt;/span&gt;&lt;span&gt;pattern_index_t &lt;/span&gt;&lt;span&gt;volatile &lt;/span&gt;*&lt;span&gt;p&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;*&lt;span&gt;n&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;uint16_t &lt;/span&gt;&lt;span&gt;record_key&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;uint32_t &lt;/span&gt;&lt;span&gt;record_id&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span&gt;pattern_t &lt;/span&gt;*&lt;span&gt;p_pattern&lt;/span&gt;&lt;span&gt;;&lt;br /&gt;&lt;/span&gt;} &lt;span&gt;pattern_index_t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;It&amp;#39;s part of a function that builds an index node after `fds_record_write_reserved` returns successfully.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I break out `sizeof(pattern_index_t)` into its own variable, I still get the error.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I should also add I am calling malloc (&amp;amp; calloc) a couple other places successfully.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: malloc causing fault in SoftDevice</title><link>https://devzone.nordicsemi.com/thread/242084?ContentTypeID=1</link><pubDate>Fri, 27 Mar 2020 12:00:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe75f7e5-b669-4fa8-b61a-7847ce7de625</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Which SDK and softdevice version are you using? Are you basing this on an SDK example?&lt;/p&gt;
&lt;p&gt;Can you post a code snippet of how you use malloc?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>