I\'m creating a source files containing buffer functionality that I want to use for my other library that I\'m creating.
It is working correctly but I\'m having tro
Once you've called free()
on the allocated pointer, attempt to make use of the pointer invokes undefined behavior. You should not be doing that.
To quote C11
standard, chapter §7.22.3.4, free()
function
The
free()
function causes the space pointed to byptr
to be deallocated, that is, made available for further allocation. [..]
It never say's anything about a cleanup, which you might be (wrongly) expecting.
Just to add clarity, calling free()
does not always actually free up the allocated physical memory. It just enables that pointer (memory space) to be allocated again (returning the same pointer, for example) for successive calls to malloc()
and family. After calling free()
, that pointer is not supposed to be used from your program anymore but C
standard does not guarantee of a cleanup of the allocated memory.