[AD] exit function mechanism

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Functions registered with _add_exit_func are called from allegro_exit, which is not just called at clean program termination, but can also be called when a fatal signal has been caught, on platforms that install signal handlers for such signals. Therefore, it is possible, and it often happens to me, that some exit function fails, segfaults, calls signal handler which calls this faulty function from allegro_exit again and again... infinite loop.

The attached patch modifies the code so that allegro_exit unregisters the function prior to calling it, preventing the above scenario to happen. Explicit unregistering from a exit function is no longer needed, nor it ever was so it's removed. Explicit unregistering of exit functions from non-exit-function code is still allowed and used somewhere.


--
Milan Mimica
http://sparklet.sf.net
Index: src/joystick.c
===================================================================
--- src/joystick.c	(revision 5789)
+++ src/joystick.c	(working copy)
@@ -203,7 +203,6 @@
 
       clear_joystick_vars();
 
-      _remove_exit_func(remove_joystick);
       _joystick_installed = FALSE;
    }
 }
Index: src/keyboard.c
===================================================================
--- src/keyboard.c	(revision 5789)
+++ src/keyboard.c	(working copy)
@@ -720,8 +720,6 @@
    clear_key();
 
    key_shifts = _key_shifts = 0;
-
-   _remove_exit_func(remove_keyboard);
 }
 
 
Index: src/config.c
===================================================================
--- src/config.c	(revision 5789)
+++ src/config.c	(working copy)
@@ -215,7 +215,6 @@
    
    argv_buf_size = 0;
 
-   _remove_exit_func(config_cleanup);
    config_installed = FALSE;
 }
 
Index: src/i386/istretch.c
===================================================================
--- src/i386/istretch.c	(revision 5789)
+++ src/i386/istretch.c	(working copy)
@@ -257,8 +257,6 @@
 	 #endif
       }
 
-   _remove_exit_func(free_stretchers);
-
    stretcher_virgin = TRUE;
 }
 
Index: src/readbmp.c
===================================================================
--- src/readbmp.c	(revision 5789)
+++ src/readbmp.c	(working copy)
@@ -189,8 +189,6 @@
    #ifdef ALLEGRO_USE_CONSTRUCTOR
       _register_bitmap_file_type_init();
    #endif
-
-   _remove_exit_func(register_bitmap_file_type_exit);
 }
 
 
@@ -245,7 +243,5 @@
       }
    
       bitmap_type_list = NULL;
-
-      _remove_exit_func(register_bitmap_file_type_exit);
    }
 #endif
Index: src/readsmp.c
===================================================================
--- src/readsmp.c	(revision 5789)
+++ src/readsmp.c	(working copy)
@@ -137,8 +137,6 @@
    #ifdef ALLEGRO_USE_CONSTRUCTOR
       _register_sample_file_type_init();
    #endif
-
-   _remove_exit_func(register_sample_file_type_exit);
 }
 
 
@@ -191,7 +189,5 @@
       }
    
       sample_type_list = NULL;
-
-      _remove_exit_func(register_sample_file_type_exit);
    }
 #endif
Index: src/graphics.c
===================================================================
--- src/graphics.c	(revision 5789)
+++ src/graphics.c	(working copy)
@@ -461,8 +461,6 @@
    if (system_driver->restore_console_state)
       system_driver->restore_console_state();
 
-   _remove_exit_func(shutdown_gfx);
-
    gfx_virgin = TRUE;
 }
 
Index: src/readfont.c
===================================================================
--- src/readfont.c	(revision 5789)
+++ src/readfont.c	(working copy)
@@ -111,8 +111,6 @@
    #ifdef ALLEGRO_USE_CONSTRUCTOR
       _register_font_file_type_init();
    #endif
-
-   _remove_exit_func(register_font_file_type_exit);
 }
 
 
@@ -166,7 +164,5 @@
       }
    
       font_type_list = NULL;
-
-      _remove_exit_func(register_font_file_type_exit);
    }
 #endif
Index: src/allegro.c
===================================================================
--- src/allegro.c	(revision 5789)
+++ src/allegro.c	(working copy)
@@ -470,7 +470,9 @@
 void allegro_exit(void)
 {
    while (exit_func_list) {
-      (*(exit_func_list->funcptr))();
+      void (*func)(void) = exit_func_list->funcptr;
+      _remove_exit_func(exit_func_list->funcptr);
+      (*(func))();
    }
 
    if (system_driver) {
@@ -565,8 +567,6 @@
 
    debug_assert_virgin = TRUE;
    debug_trace_virgin = TRUE;
-
-   _remove_exit_func(debug_exit);
 }
 
 
Index: src/sound.c
===================================================================
--- src/sound.c	(revision 5789)
+++ src/sound.c	(working copy)
@@ -703,7 +703,6 @@
       digi_driver->exit(FALSE);
       digi_driver = &digi_none; 
 
-      _remove_exit_func(remove_sound);
       _sound_installed = FALSE;
    }
 }
Index: src/file.c
===================================================================
--- src/file.c	(revision 5789)
+++ src/file.c	(working copy)
@@ -1084,9 +1084,6 @@
 {
    RESOURCE_PATH *node = resource_path_list;
    
-   if (node)
-      _remove_exit_func(destroy_resource_path_list);
-   
    while (node) {
       resource_path_list = node->next;
       _AL_FREE(node);
Index: src/timer.c
===================================================================
--- src/timer.c	(revision 5789)
+++ src/timer.c	(working copy)
@@ -612,7 +612,6 @@
    /* make sure subsequent remove_int() calls don't crash */
    clear_timer_queue();
 
-   _remove_exit_func(remove_timer);
    _timer_installed = FALSE;
 }
 
Index: src/mouse.c
===================================================================
--- src/mouse.c	(revision 5789)
+++ src/mouse.c	(working copy)
@@ -1170,8 +1170,6 @@
       destroy_bitmap(mtemp);
       mtemp = NULL;
    }
-
-   _remove_exit_func(remove_mouse);
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/