AnsweredAssumed Answered

Why sometimes the Heap Pointer will be pointed to 0x000000?

Question asked by Lingjun Kong on Jul 28, 2017
Latest reply on Jul 31, 2017 by Daniel Glasser

in my function, several heap pointers are defined like this



when I comment the 111 line. the whole code works well. But when I add this line, the pointer Test_feature, ZeroCenter_Parameters, C1K,C1B will all, or sometimes partly, point to 0x000000.

eventually in 2 debug with the same code, it may different.

so the Question is:

In general, What will let the Heap pointer point to 0x00000? before free.


for my observation, the heap size is enough on my project (HEAP SIZE=0x8000, the same as stack size). I'm using STM32F746NG-Discovery Board so the RAM Space(at least 240KB for algorithm) is also enough. So it may be the problem of the IDE or Compiler?


My environment:

   KeilV523, STM32F746NG-Disco, Win10 Edu.




for more general situation. this code.


void heaptest()
int *a;

int i=1024;



0x08004468 BD10      POP           {r4,pc}

   176:         a=(int*)malloc(1024*4);



0x0800446A F44F5080  MOV           r0,#0x1000

   174: {

   175:         int *a;

   176:         a=(int*)malloc(1024*4);


0x0800446E B510      PUSH          {r4,lr}

0x08004470 F000F8B6  BL.W          malloc (0x080045E0)

   178:         int i=1024;

0x08004474 F44F6180  MOV           r1,#0x400

   179:         while(i--)

   180:         {


0x08004478 E000      B             0x0800447C

   182:                 *a=i;

   183:                 //printf("%d",*a);

   184:                 a++;

   185:         }


0x0800447A C002      STM           r0!,{r1}

0x0800447C 1E49      SUBS          r1,r1,#1

0x0800447E D2FC      BCS           0x0800447A

   187:                 free(a);

   188: }

   189: int main(void)

   190: {

   191:   SCB_EnableICache();

   192:   SCB_EnableDCache();

0x08004480 E8BD4010  POP           {r4,lr}

0x08004484 F7FFBF08  B.W           free (0x08004298)


before the free operation, the pointer will be pointed to 0x00000. who did that?