summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2024-04-04 15:20:55 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2024-04-30 11:02:13 +0900
commit08a71c8f8d2d73bc1ba7d6b2a58b9ce30184c471 (patch)
tree31911b276cd39986fee04af0edc2a56c36b86379 /src
parentf5bf794e23c940b8654f3f64ad62a0870cbf91c9 (diff)
downloadtqt3-08a71c8f8d2d73bc1ba7d6b2a58b9ce30184c471.tar.gz
tqt3-08a71c8f8d2d73bc1ba7d6b2a58b9ce30184c471.zip
Correctly release glib mainloop and gsource, to avoid memory leaks
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src')
-rw-r--r--src/kernel/qeventloop_glib_p.h1
-rw-r--r--src/kernel/qeventloop_unix_glib.cpp4
-rw-r--r--src/kernel/qeventloop_x11_glib.cpp18
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 )