Checking if something was malloced

后端 未结 8 677
面向向阳花
面向向阳花 2021-01-12 07:06

Given a pointer to some variable.. is there a way to check whether it was statically or dynamically allocated??

相关标签:
8条回答
  • 2021-01-12 07:32

    Can you hook into malloc() itself, like the malloc debuggers do, using LD_PRELOAD or something? If so, you could keep a table of all the allocated pointers and use that. Otherwise, I'm not sure. Is there a way to get at malloc's bookkeeping information?

    0 讨论(0)
  • 2021-01-12 07:37

    1.) Obtain a map file for the code u have.

    2.) The underlying process/hardware target platform should have a memory map file which typically indicates - starting address of memory(stack, heap, global0, size of that block, read-write attributes of that memory block.

    3.) After getting the address of the object(pointer variable) from the mao file in 1.) try to see which block that address falls into. u might get some idea.

    =AD

    0 讨论(0)
提交回复
热议问题