diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-04-04 15:20:55 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-05-01 13:44:49 +0900 |
commit | 8141b881e3f6088c9980c1ee41f8e926e18cc208 (patch) | |
tree | 0d80b1d97e960fcb165f0fc49f2c77a5523bb438 | |
parent | 73c9765982a42ac7b1eb1608b8d684701dc0b9d6 (diff) | |
download | tqt3-8141b881e3f6088c9980c1ee41f8e926e18cc208.tar.gz tqt3-8141b881e3f6088c9980c1ee41f8e926e18cc208.zip |
Correctly release glib mainloop and gsource, to avoid memory leaks
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 08a71c8f8d2d73bc1ba7d6b2a58b9ce30184c471)
-rw-r--r-- | src/kernel/qeventloop_glib_p.h | 1 | ||||
-rw-r--r-- | src/kernel/qeventloop_unix_glib.cpp | 4 | ||||
-rw-r--r-- | src/kernel/qeventloop_x11_glib.cpp | 18 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/kernel/qeventloop_glib_p.h b/src/kernel/qeventloop_glib_p.h index 6c5fbbbb8..b5dbbada1 100644 --- a/src/kernel/qeventloop_glib_p.h +++ b/src/kernel/qeventloop_glib_p.h @@ -116,6 +116,7 @@ public: // main context GMainContext *ctx; + GMainLoop *mainloop; bool ctx_is_default; }; diff --git a/src/kernel/qeventloop_unix_glib.cpp b/src/kernel/qeventloop_unix_glib.cpp index f84339651..d86ba14fc 100644 --- a/src/kernel/qeventloop_unix_glib.cpp +++ b/src/kernel/qeventloop_unix_glib.cpp @@ -439,8 +439,10 @@ TQEventLoopPrivate::TQEventLoopPrivate() { x_gPollFD.events = 0; x_gPollFD.revents = 0; #endif // TQ_WS_X11 + gSource = nullptr; singletoolkit = TRUE; - ctx = 0; + ctx = nullptr; + mainloop = nullptr; ctx_is_default = false; reset(); } diff --git a/src/kernel/qeventloop_x11_glib.cpp b/src/kernel/qeventloop_x11_glib.cpp index 4b44fe8f2..a13dbeebf 100644 --- a/src/kernel/qeventloop_x11_glib.cpp +++ b/src/kernel/qeventloop_x11_glib.cpp @@ -226,7 +226,7 @@ void TQEventLoop::init() printf("inside init(1)\n"); #endif - g_main_loop_new (d->ctx, 1); + d->mainloop = g_main_loop_new (d->ctx, 1); g_source_attach( (GSource*)qtGSource, d->ctx ); d->gSource = (GSource*)qtGSource; @@ -258,10 +258,22 @@ void TQEventLoop::cleanup() // cleanup the X11 parts of the event loop d->xfd = -1; + // stop polling the GSource + g_source_remove_poll(d->gSource, &d->threadPipe_gPollFD); + g_source_remove_poll(d->gSource, &d->x_gPollFD); + g_source_destroy(d->gSource); + + // unref the main loop + g_main_loop_unref(d->mainloop); + d->mainloop = nullptr; + + // unref the gsource + g_source_unref(d->gSource); + d->gSource = nullptr; + // unref the main context g_main_context_unref(d->ctx); - - // todo: destroy gsource + d->ctx = nullptr; } bool TQEventLoop::processEvents( ProcessEventsFlags flags ) |