This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC1352P7: Problem about malloc fails.

Part Number: CC1352P7
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hi TI,

I use simplelink_cc13x2_26x2_sdk_5_20_00_52 and CC1352P7.

Now I have a problem about malloc function.

In my application, I need to use malloc 4~6 times.

The pseudo code is as below:

void foo(void)
{
    uint8_t *p1 = malloc(hundred bytes);
    uint8_t *p2 = malloc(hundred bytes);
    uint8_t *p3 = malloc(hundred bytes);
    uint8_t *p4 = malloc(hundred bytes);
    uint8_t *p5 = malloc(hundred bytes);
    uint8_t *p6 = malloc(hundred bytes);
    
    /*Some code using the above 6 pointers*/
    
    if (p1 != NULL) {free(p1);}
    if (p2 != NULL) {free(p2);}
    if (p3 != NULL) {free(p3);}
    if (p4 != NULL) {free(p4);}
    if (p5 != NULL) {free(p5);}
    if (p6 != NULL) {free(p6);}
}

The above code executes each second.

The phenomenon is, sometime the program may halt in a malloc and then restart in a few seconds.

Sometimes, the program may run for several hours and then halt, other times, the program may only run for a few seconds and then halt.

Here is a print log of the program running for a few seconds.

The log consists of 3 times mallocs.

This is the first 4 mallocs:

After one second, the second 6 mallocs:

After one second again, the third 6 mallocs:

You can see that, after 4 mallocs, program exception occurs, it halts and then restart.

I have test this problem for days. Each time program halts, it stops in the malloc function.

In the print log, we can see each pointer's address in RAM from malloc, and the addresses indicate that there should be no memory leak.

The program have about 40kB heap size, and the total malloc size in print log is about 11kB, so there is enough avaliable heap size.

So, how to further investigate this problem, for example, can I know the remaining size of the heap in real time, or any other method?

Thank you.