https://bugs.winehq.org/show_bug.cgi?id=48482
--- Comment #16 from Federico Dossena info@fdossena.com --- (In reply to Stefan Dösinger from comment #15)
Use after free should be caught by WINEDEBUG=warn+heap.
Add some extra ERR lines to HeapAlloc to make sure you're actually getting a NULL allocation back. If you do, you can see what the parameters are and why it is failing.
If you suspect use after free you can try to make HeapFree do nothing. You might die from out of memory though.
There are other alloc APIs, most importantly VirtualAlloc and GlobalAlloc. But the first one is usually not used for regular work allocations (but e.g. for allocating memory for dynamically generated code or hardware I/O) and GlobalAlloc is more a Win16 thing if I am not mistaken.
The game seems to use the same malloc and free functions, so I was able to modify them.
I'm attaching a 7z file containing the diffs files to apply to swkotor.exe to do the double mallocs and to disable the free function.
The game still crashes at the same location, so I guess it has nothing to do with memory allocations. I noticed 2 things however: the crash is always at the end of the loading, which is where some large textures are allocated and pbuffers are used. This used to be a problem with Mesa, although they seem to have fixed it over a year ago. In the terminal it says something about a WGL function being a partial stub, could this be the problem?