Bug 255118

Summary: Memory leak in KLineEdit
Product: [Unmaintained] kdelibs Reporter: Joris Guisson <joris.guisson>
Component: kdeuiAssignee: kdelibs bugs <kdelibs-bugs>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 4.5   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Joris Guisson 2010-10-24 16:31:44 UTC
Version:           4.5 (using KDE 4.5.1) 
OS:                Linux

While running ktorrent under valgrind I encountered the following leak:

==13004== 132 (32 direct, 100 indirect) bytes in 1 blocks are definitely lost in loss record 1,046 of 1,285
==13004==    at 0x402569A: operator new(unsigned int) (vg_replace_malloc.c:255)
==13004==    by 0x49ED5B5: KLineEdit::init() (klineedit.cpp:270)
==13004==    by 0x49F6196: KLineEdit::KLineEdit(QWidget*) (klineedit.cpp:238)
==13004==    by 0x42BB374: kt::HintLineEdit::HintLineEdit(QWidget*) (hintlineedit.cpp:50)
==13004==    by 0x808C39A: kt::QueueManagerWidget::QueueManagerWidget(kt::QueueManager*, QWidget*) (queuemanagerwidget.cpp:55)
==13004==    by 0x807FC9A: kt::TorrentActivity::TorrentActivity(kt::Core*, kt::GUI*, QWidget*) (torrentactivity.cpp:79)
==13004==    by 0x807C7BA: kt::GUI::GUI() (gui.cpp:96)
==13004==    by 0x807DF84: kt::App::newInstance() (app.cpp:58)
==13004==    by 0x490ACAF: KUniqueApplication::Private::_k_newInstanceNoFork() (kuniqueapplication.cpp:373)
==13004==    by 0x490AD23: KUniqueApplication::qt_metacall(QMetaObject::Call, int, void**) (kuniqueapplication.moc:72)
==13004==    by 0x51A0D49: QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) (qmetaobject.cpp:237)
==13004==    by 0x51AC225: QMetaCallEvent::placeMetaCall(QObject*) (qobject.cpp:534)
==13004==    by 0x51ADAC1: QObject::event(QEvent*) (qobject.cpp:1219)
==13004==    by 0x519AE8A: QCoreApplication::event(QEvent*) (qcoreapplication.cpp:1561)
==13004==    by 0x54A5C53: QApplication::event(QEvent*) (qapplication.cpp:2439)
==13004==    by 0x54A277B: QApplicationPrivate::notify_helper(QObject*, QEvent*) (qapplication.cpp:4396)
==13004==    by 0x54A87CD: QApplication::notify(QObject*, QEvent*) (qapplication.cpp:3798)
==13004==    by 0x807DE8F: kt::App::notify(QObject*, QEvent*) (app.cpp:97)
==13004==    by 0x519AFEA: QCoreApplication::notifyInternal(QObject*, QEvent*) (qcoreapplication.cpp:732)
==13004==    by 0x519E24A: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (qcoreapplication.h:215)
==13004==    by 0x519E40C: QCoreApplication::sendPostedEvents(QObject*, int) (qcoreapplication.cpp:1266)
==13004==    by 0x51C9D03: postEventSourceDispatch(_GSource*, int (*)(void*), void*) (qcoreapplication.h:220)
==13004==    by 0x69C35E4: g_main_context_dispatch (in /lib/libglib-2.0.so.0.2400.1)
==13004==    by 0x69C72D7: ??? (in /lib/libglib-2.0.so.0.2400.1)
==13004==    by 0x69C74B7: g_main_context_iteration (in /lib/libglib-2.0.so.0.2400.1)
==13004==    by 0x51C97F4: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (qeventdispatcher_glib.cpp:415)
==13004==    by 0x5563DE4: QGuiEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (qguieventdispatcher_glib.cpp:204)
==13004==    by 0x5199A98: QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (qeventloop.cpp:149)
==13004==    by 0x5199F19: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (qeventloop.cpp:201)
==13004==    by 0x519E4CE: QCoreApplication::exec() (qcoreapplication.cpp:1009)
==13004==    by 0x54A15A6: QApplication::exec() (qapplication.cpp:3672)
==13004==    by 0x806D08E: main (main.cpp:175)

There is no further mention in the valgrind log that the KLineEdit itself is leaked. So it would appear that there is a leak internally in KLineEdit. 

Reproducible: Always
Comment 1 Aaron J. Seigo 2010-10-26 18:53:31 UTC
SVN commit 1190023 by aseigo:

clean up the style created by the widget; the style itself doesn't set a parent widget. i believe this is due to the usual semantics of QStyle which is to be shared amongst widgets, making automatic QObject based deletion non-standard and even dangerous for QStyles. in this case, though, it does need to be deleted as there is a 1:1 relationship between the line edit and the style object. so to keep memory from leaking and to keep with the usual QStyle semantics, leave it up to KLineEdit to clean it up.

KLineEdit unit tests still pass after this commit.

thanks to Joris Guisson for the valgrinding and reporting.

BUG:255118


 M  +1 -0      klineedit.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1190023
Comment 2 Joris Guisson 2010-10-26 19:59:05 UTC
Nice, a quick fix