wrye-bash / CBash

Home of CBash.DLL sources
GNU General Public License v2.0
9 stars 4 forks source link

Assertion failed on pointer delete[] while running in Debug mode #16

Closed leandor closed 4 years ago

leandor commented 7 years ago

Error: image

Code

NonNullStringRecord::~NonNullStringRecord()
    {
    if(DiskSize == 0)
        delete []_value;  // <<<< HERE
    }

Probably caused by double delete of that pointer.

leandor commented 7 years ago

Well, it took me some time, but I finally found the reason for that assert. (And I'm glad I did, as I didn't want to do big changes before finishing this issue)

It was because sometimes there are records that should contain a SCXI field, but the size of this field it's zero. And the code wasn't taking into account that condition, and since the condition for freeing its internal value buffer was that the Stored Size (meaning, the size of the element in the shared buffer) were 0, at the end it was trying to free a pointer that didn't point to the actual HEAP, but instead it was a sub-pointer to the shared buffer memory (filemap).

Infernio commented 4 years ago

Closed in 4587dd964c0d01a63c2b3e892cc46a00d0c41c86.