Correctly release glib mainloop and gsource, to avoid memory leaks

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Michele Calgaro 1 month ago
parent 7563c4825f
commit f52f239f59
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -116,6 +116,7 @@ public:
// main context
GMainContext *ctx;
GMainLoop *mainloop;
bool ctx_is_default;
};

@ -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();
}

@ -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 )

Loading…
Cancel
Save