runtime error: double free

BlitzMax Forums/BlitzMax Programming/runtime error: double free

Warner(Posted 2009) [#1]
When I close down my program, I get the following message:

runtime(657,0xa04cbf60) malloc: *** error for object 0x15d178f0: double free
*** set a breakpoint in malloc_error_break to debug


Does anybody know what this means?


Brucey(Posted 2009) [#2]
It means there's a bug somewhere.

Are you using any 3rd-party modules, or MaxGUI ?


Warner(Posted 2009) [#3]
Yes, I am using BriskVM for this project.
Does this error mean something along the lines of: memory that was claimed by malloc is freed twice?
Then how would that translate into BMax?
The script engine uses a lot of int-to-object and object-to-int conversions, but in the end it calls Release to release the integer handles.
I can imagine that this problem is related to that.
Especially since when I don't compile and run the main script, the error doesn't appear.


Brucey(Posted 2009) [#4]
Does this error mean something along the lines of: memory that was claimed by malloc is freed twice?


Ripped from Wikipedia :

Commonly, the system may have reused freed memory for other purposes. Therefore, writing through a pointer to a deallocated region of memory may result in overwriting another piece of data somewhere else in the program. Depending on what data is overwritten, this may result in data corruption or cause the program to crash at a later time. A particularly bad example of this problem is if the same pointer is passed to free twice, known as a double free. To avoid this, some programmers set pointers to NULL after passing them to free: free(NULL) is safe (it does nothing). However, this will not protect other aliases to the same pointer from being doubly freed.



In BlitzMax, it's usually seen when something is still being used after it was actually freed. Then it tries to free it again - because it thinks it is using it.

Bad stuff :-)


Warner(Posted 2009) [#5]
Ah .. Wikipedia .. why didn't I look there? :)
Thanks, I think I understand. The problem is gone now.
In my script, I used two variables to refer to the same object.
I think the VM tried to Release both objects. (integer Release)
After I set one of the two variables to Null before ending the script, the error didn't appear anymore.