[Mono-bugs] [Bug 31333][Nor] Changed - GC problem with Console.WriteLine in the finalization code.

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
26 Oct 2002 10:53:20 -0000


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by ettore@ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=31333

--- shadow/31333	Fri Sep 27 20:31:51 2002
+++ shadow/31333.tmp.19229	Sat Oct 26 06:53:20 2002
@@ -110,6 +110,26 @@
 Basically in the course of execution the GC is run to free up resources and this 
 results in a cyclic loop ad infinitum, because the GC does not have enough 
 resources to run the finalization code.  So it attempts to free up resources to run 
 the finalization code, but it doesn't have enough resources to run ... so it attempts 
 to free up resources ... but it doesn't have enough ... You get the picture ;) 
  
+
+------- Additional Comments From ettore@ximian.com  2002-10-26 06:53 -------
+Actually, I believe it's even more simple than that.
+
+Before allocating memory, GC_malloc() notifies the pending finalizers
+(see malloc.c:186 in 6.1 final).
+
+But if a finalizer needs to allocate something, it will spawn another
+GC_malloc(), which in turn will try to flush more pending
+finalizations, which in turn can invoke GC_malloc()...
+
+For this reason, if we get in a situation where there are enough
+finalizers using GC_malloc() and they are invoked in the right order,
+the stack can overflow and lead to this crash.
+
+The attached patch (to libgc 6.1) prevents this from happening by
+making sure that there is at most one nested finalize notification.
+
+Unfortunately, I don't know the Boehm GC code, so I am not sure that
+this is the right fix...