From 1278ed0dad0a51d280d7b8b934a9280b459b107c Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Sat, 16 Mar 2024 08:43:59 +0300 Subject: [PATCH] Fix a small memory leak in xim plugin TQXIMInputContext::setHolderWidget() function may be (and actually is) called more than once. This results in multiple instances of the same object being added to ximContextList. But the destructor removes only one instance, which effectively results in leak of several bytes whenever a window is opened. Signed-off-by: Alexander Golubev --- plugins/src/inputmethods/xim/qximinputcontext_x11.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/src/inputmethods/xim/qximinputcontext_x11.cpp b/plugins/src/inputmethods/xim/qximinputcontext_x11.cpp index e9dbcdd2..20ca4424 100644 --- a/plugins/src/inputmethods/xim/qximinputcontext_x11.cpp +++ b/plugins/src/inputmethods/xim/qximinputcontext_x11.cpp @@ -343,6 +343,12 @@ TQXIMInputContext::TQXIMInputContext() { if(!isInitXIM) TQXIMInputContext::init_xim(); + +#if !defined(TQT_NO_XIM) + if( ! ximContextList ) + ximContextList = new TQPtrList; + ximContextList->append( this ); +#endif // !TQT_NO_XIM } @@ -424,10 +430,6 @@ void TQXIMInputContext::setHolderWidget( TQWidget *widget ) // when resetting the input context, preserve the input state (void) XSetICValues((XIC) ic, XNResetState, XIMPreserveState, (char *) 0); - - if( ! ximContextList ) - ximContextList = new TQPtrList; - ximContextList->append( this ); #endif // !TQT_NO_XIM }