[blue]Just recently I have come across a problem in MFC code. There is a method:[/blue]
CTreeCtrl::GetItemData (HTREEITEM hItem)
This method will return garbage pointer in the case of invalid HTREEITEM passed in. It first will fire an ASSERT() in debug build, but then return uninitialized variable from stack.
In our case (at my work) we used the 'delete' statement on the return value and obviously heap corruption followed and our system failed at some point after that.
I understand that it is our code which passes the invalid HTREEITEM (and we will locate and fix that code), but MFC is a serious library - not some wacked free library from the Web. It should not fail in that manner. Instead, it should return NULL from that method.
To fix that issue I wrote my own GetItemData() with a checking of the return value from TVM_GETITEM message and that saved the day (for now).