[Mono-dev] crashes in glib hangs (not exits) program

D Bera dbera.web at gmail.com
Sun Apr 20 15:10:35 EDT 2008


Hi,
  I noticed that some unmanaged crashes in glib could leave the
program running but hanged. See below for a sample program (the bad
g_free was used to deliberately crash).

Putting the g_free in a "try { g_free (obj); } catch { }" correctly
aborts the program. From its stacktrace it looks like mono somehow
hangs when it tries to print the managed stacktrace (I noticed
g_spawn_command_line_sync). Is that the reason and the "try ... catch
..." is the recommended way to abort after a potential crash in glib ?

It is actually terribly inconvenient if programs do not exit when
crashed :-). Is there any way I can force this behaviour ?

Thanks,
- dBera

---------------------8<-----------------
using System;
using System.Runtime.InteropServices;

class GlibCrash {
        [DllImport("libgobject-2.0.so.0")]
        static extern void g_type_init ();

        [DllImport("libgobject-2.0.so.0")]
        static extern IntPtr g_string_new (string str);

	// UNCOMMENT this to exit the program on crash; comment to hang
	// THIS can only be observed on mono 1.2.6 and not in 1.9
        //[DllImport("libgobject-2.0.so.0")]
	//static extern void g_string_free(IntPtr obj, bool free_segment);

        [DllImport("libgobject-2.0.so.0")]
        static extern void g_free (IntPtr obj);

	static void Main() {
		g_type_init ();
		IntPtr obj = g_string_new("hello world");
		g_free(obj);
	}
}
---------------------8<----------------------

-- 
-----------------------------------------------------
Debajyoti Bera @ http://dtecht.blogspot.com
beagle / KDE fan
Mandriva / Inspiron-1100 user


More information about the Mono-devel-list mailing list