I created some utilities which
help me to handle the management of a DinamicList. In the section that I
use to handle the removing of a element in a list, if there is
a element added that is stored in the stack, when I call free()
an undefined behaviour is reached.
Surfing on the net I found out that there aren't ways to determine whether a pointer points to stack memory or heap memory.
So I think that to solve this problem I have to handle
the error generated from free()
. Is there a way to handle that exception when I call free()
?
No.
You need to not call free()
for non heap pointers. Easiest way is let whoever allocated the memory take care of freeing it. I.e. your utilities look after whatever memory they allocate but someone else looks after the memory passed to your utilities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With