This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Dynamically allocated data get overwritten

--- Close. Cannot continue this case due to inability to share code (company policy). ---


Hi, I am writing an application where I need to parse data into dynamically allocated structs at system initialization.

I have observed that some of my dynamically allocated uint8_t array got their first elements somehow overwritten. I am 100% certain I do not directly do anything to change the data.

For more detail, take a look at this UART log here.

parse key 0 return: 0x00
parse key 0 return: 0x00
parse key 0 return: 0x30

parse key 1 return: 0x11 0xDA 0x27 0x00 0xC5 0x00 0x00 0xD7
parse key 1 return: 0x10 0x00 0x00 0x00 0xC5 0x00 0x00 0xD7
parse key 1 return: 0x10 0x00 0x00 0x00 0xC5 0x00 0x00 0xD7

parse key 2 return: 0x11 0xDA 0x27 0x00 0x42 0x00 0x00 0x54
parse key 2 return: 0x11 0xDA 0x27 0x00 0x42 0x00 0x00 0x54
parse key 2 return: 0x11 0xDA 0x27 0x00 0x42 0x00 0x00 0x54

parse key 3 return: 0x11 0xDA 0x27 0x00 0x00 0x08 0x00 0x00 0x00 0x00 0x00 0x06 0x60 0x00 0x00 0xC1 0x80 0x00 0x00
parse key 3 return: 0x11 0xDA 0x27 0x00 0x00 0x08 0x00 0x00 0x00 0x00 0x00 0x06 0x60 0x00 0x00 0xC1 0x80 0x00 0x00
parse key 3 return: 0x11 0xDA 0x27 0x00 0x00 0x08 0x00 0x00 0x00 0x00 0x00 0x06 0x60 0x00 0x00 0xC1 0x80 0x00 0x00

The log is printed at various point of the data initialization process. Each data is finished initialized before my application work on the next one (parse #2 is not started until parse #1 is done, etc.).

As you can see for parse #0, the data got corrupted before the 3rd log point. But for parse #1, the corruption happened before the 2nd log. Yet for parse #2 and #3, no corruption happened at all.

I was suspecting that this is due to a stack overflow. But given that data #2 and #3 which was parsed AFTER the corruption for data #0 and #1 happen, that seems not to be the case.

Any pointer to debug this issue is greatly appreciated.

I am working on a nrf51 DK without any SoftDevice.

  • Is it possible for you to share some code showing how you do this?

  • Hi Martin, Because the code having issue is a part of our company's application, I had to extract said code out and rename stuffs a little. But I cannot reproduce the problem with the extracted code. So I am at a bind there.

  • I closed the question because I could only submit code if I use the support portal.

    But on another note, I rewrote the entire parsing section, and this time I had malloc returns NULL instead of running into these randomly corrupted data.

    Could it be that with my older code, I also ran out of heap and old data was randomly rewritten somehow and got corrupted? Could that happened and results in the symptoms I described here?

Related