C Memory Leaks – free() Not Freeing Up Memory Properly

c++freemallocmemory-leaks

I'm trying to free up the memory I've allocated with malloc, but the free command doesn't seem to do its job properly according to Eclipse's debugger. How's this possible?

Below is a screenshot of my debugger after it supposedly freed up seCurrent->student->year, which is clearly not the case. year was allocated using malloc.

alt text http://img693.imageshack.us/img693/7840/codeo.png

Best Answer

free() does not normally change any values in your program - it just makes adjustments to the C runtime heap. This means that the values in the memory that was just freed are retained. However, attempts to access them from your code lead to undefined behaviour.

Related Question