|
You cannot free memory which you have not gotten from the heap. Local variables such as tempBuffer are autovariables. These are allocated (in most implementations, on the stack) when the function is entered. They are deallocated when the function returns.
When you use free, you are telling the system to free heap memory located at the pointer that you received when the memory was allocated. Since the auto variable was not allocated from the heap, the heap has no record regarding it, and has little choice but to run off into the weeds and puke on its shoes.
|