From 2bb6a6f6a45ddc4298f253fbcd7d4778ca861f8d Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 11 May 2018 15:04:50 +0200 Subject: ossig: Don't leak the callbacks in case the event loops are not stopped through SIGINT. Fixes #219 We didn't remove them if the event loops returned normally. This also fixes a small race where a SIGINT gets ignored right after the yield check and before the old handler is reinstated. Check after the signal handler is switched back instead. This resulted in GLib.MainLoop and Gio.Aplication instances leaking. --- gi/_ossighelper.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gi/_ossighelper.py b/gi/_ossighelper.py index 5176e97c..213f0965 100644 --- a/gi/_ossighelper.py +++ b/gi/_ossighelper.py @@ -224,8 +224,9 @@ def register_sigint_fallback(callback): try: yield finally: + cb = _callback_stack.pop() if _sigint_called: - _callback_stack.pop()() + cb() else: # There is a signal handler set by the user, just do nothing yield @@ -242,9 +243,11 @@ def register_sigint_fallback(callback): _callback_stack.pop()() _callback_stack.append(callback) - with sigint_handler_set_and_restore_default(sigint_handler): - try: + try: + with sigint_handler_set_and_restore_default(sigint_handler): yield - finally: - if _sigint_called: - signal.default_int_handler(signal.SIGINT, None) + finally: + if _sigint_called: + signal.default_int_handler(signal.SIGINT, None) + else: + _callback_stack.pop() -- cgit v1.2.1