Possible bug in MT memory management.

Archives Forums/BlitzMax Bug Reports/Possible bug in MT memory management.

Corum(Posted 2010) [#1]
Hi,
I'm working (very slowly) on a game project.
To speedup AI processing, I was considering to approach MT features.
My project is working perfectly in standard "single threaded mode".
As a start, I just recompiled all the mods in MT version and did a simple build of my sources - no changes at all - with MT feature enabled.
My dev environment is:
Leopard 10.5.8 - XCode 3.1.3 - BlitzMax 1.36

My program crashes, giving as output the following malloc double free error, for about 20 times:


The Mac OSX crash report states the following:


What's wrong, in your opinion?
Thanks.


Brucey(Posted 2010) [#2]
Ooooh... double free... that's not so good.

Does it always fall over with a similar stack-trace?


Corum(Posted 2010) [#3]
Hi Brucey! :)
You had the right intuition about the crash report creativity. :-)
The answer is no. Sometimes it crashes on certain calls, sometimes on others, in an absolutely arbitrary fashion.
Mmhh I suppose it is bad. It sounds sooo bad. :-)

This time was:
Thread 0 Crashed:
0   main.mt                       	0x0002b6ed unzCloseCurrentFile + 61
1   main.mt                       	0x00023174 _ifsogui_gui_TZipStream_Close + 31
2   main.mt                       	0x000228cf _ifsogui_gui_TBufferedStream_Close + 20
3   main.mt                       	0x0011939a 188 + 0
4   main.mt                       	0x0011c0ff collectMem + 591
5   main.mt                       	0x0011c27f allocMem + 335
6   main.mt                       	0x0011c50c bbGCAllocObject + 44
7   main.mt                       	0x0011d783 allocateArray + 195
8   main.mt                       	0x0011d977 bbArrayNew1D + 23
9   main.mt                       	0x00120959 bbStringSplit + 217
10  main.mt                       	0x00025265 1738 + 31
11  main.mt                       	0x00010940 _ifsogui_slider_ifsoGUI_Slider_LoadTheme + 28
12  main.mt                       	0x00010dd1 501 + 0
13  main.mt                       	0x00027db4 255 + 0
14  main.mt                       	0x000037cb _bb_TGUIWrapper_InitGui + 78



Otus(Posted 2010) [#4]
Do you do anything complicated in any of your Delete methods?


Corum(Posted 2010) [#5]
@Otus: the sources come from an external mod, and are covered by copyrights, so I cannot be more specific..
But IMHO the problem is related to GC.
Looking at the library code, in every method, the temporary objects are allocated as Local, and often set to Null in the end.
There are no Delete or similar methods occurrences.
I talk about temporary initialization object because application doesn't even starts, but crashes during early steps of init phase...

NOTE: the library author did a try under windows (same version of Bmax I'm using on Mac), with an example source that actually crashes under Mac environment, with no issues at all.


Corum(Posted 2010) [#6]
Ok, I restricted the field to a module wrapped from C.
If I use to load a theme without the zipstream feature, but straight from filesystem, my MT app doesn't crash anymore.
For what I know about it, it loads the .zip, extracting it to memory and opening a stream from there. Many chances to break something.
I'm going to investigate further.
Thanks. :)


Brucey(Posted 2010) [#7]
I looks like there's stuff going on in that ifsogui module that is causing your problems.

Does it always crash with a double free?


TaskMaster(Posted 2010) [#8]
Brucey, the failure actually occurs within the zipstream module which makes some standard C calls. It works in multi-threaded if he doesn't use a zip file and it works with a zip file if he doesn't use multi-threading.

The weird thing about it is that it works fine in Windows, I do not have a mac to debug it with. When I get a chance (hopefully tonight), I am going to try it on Linux. And I do have a mac VM I might be able to try it on.


Brucey(Posted 2010) [#9]
Which zipstream module?

I can test it if I know what I need to replicate it in a simple example.


Corum(Posted 2010) [#10]
The one from Koriolis.
And of course, always double free issue, and it has problems under windows too.
Sadly, if you take the module and build'n run the basic examples, cannot reproduce the messy behaviour.


marksibly(Posted 2010) [#11]
Hi,

Are you actually using threads at all?


Corum(Posted 2010) [#12]
Hi Mark. :)
No, as I said in OP, I simply made an MT build of my working project, with future plans to parallelize several AI stuff by using MT features.
If I rollback to 1.34, I can safely run the same project with MT option enabled.

Bye.


TaskMaster(Posted 2010) [#13]
That is the same result I am getting. And it turns out that it does do it in Windows, so it is not just a mac problem. When I first tested, I was not actually using the zipstream.

So, to explain it clearly: We take a program in Single Thread, using the koriolis.zipstream and it works fine. Then we recompile with multi-thread and it fails. The failure occurs when using LoadImage. I step through the app and it makes it 3 or 4 lines past the LoadImage sometimes and sometimes it crashes right at the end of the LoadImage. This is why it seems to be a GC problem.

I do not know if you are familiar with the zipstream module, but it is mostly C code.