diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2018-05-11 15:04:50 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2018-05-11 15:12:05 +0200 |
commit | 2bb6a6f6a45ddc4298f253fbcd7d4778ca861f8d (patch) | |
tree | 4de103792eede97c6397b816b5b0c2afa9417873 | |
parent | 85b199116813a33a1d9aeae1b89f80938d80d36c (diff) | |
download | pygobject-sigint-fallback-leak.tar.gz |
ossig: Don't leak the callbacks in case the event loops are not stopped through SIGINT. Fixes #219sigint-fallback-leak
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.
-rw-r--r-- | gi/_ossighelper.py | 15 |
1 files 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() |