Version: unspecified (using KDE 4.4.2) OS: Linux The ktorrent plasmoid has a pretty big memory leak which reaches several MB in a few minutes (or hundreds of MB overnight). I caught this when adding the plasmoid to the desktop while ktorrent was active (with at least one active torrent), and seeing plasma-desktop grow to hundreds of MB overnight (and never go back down), and later recreating this scenario. Reproducible: Always Steps to Reproduce: 1. Run KTorrent with at least one active torrent (download or seed). 2. Run "valgrind --tool=memcheck --leak-check=full plasmoidviewer ktorrent" 3. Let the plasmoid run for a few minutes. 4. Close the plasmoid. 5. Observe the valgrind results. Actual Results: There are several reported leaks, but the largest one is of several MB (and continues to grow with time). Expected Results: No memory leaks! Looking at the valgrind results for the largest leak: ==26361== 4,680,423 (29,664 direct, 4,650,759 indirect) bytes in 927 blocks are definitely lost in loss record 1,024 of 1,024 ==26361== at 0x4C28CC1: operator new(unsigned long) (vg_replace_malloc.c:261) ==26361== by 0x222D663C: bt::BDecoder::parseDict() (in /usr/lib/libbtcore.so.12.3.0) ==26361== by 0x222D6484: bt::BDecoder::decode() (in /usr/lib/libbtcore.so.12.3.0) ==26361== by 0x240E338B: ??? (in /usr/lib/kde4/plasma_engine_ktorrent.so) ==26361== by 0x240DBD8B: ??? (in /usr/lib/kde4/plasma_engine_ktorrent.so) ==26361== by 0x5576F05: Plasma::DataEnginePrivate::internalUpdateSource(Plasma::DataContainer*) (dataengine.cpp:567) ... Looking at the code it seems like torrentdbusinterface.cpp calls BDecoder::decode(), but never deletes the returned dictionary's (or other return type if exception is thrown), thus leaking on every update. disclaimer: I don't have all the debug info available, and it's the first time I've used valgrind, and I know nothing of the libktorrent memory management conventions, so I hope I understood this correctly. In any case, whether the analysis is correct or not - the plasmoid is definitely leaking, possibly in multiple places.
SVN commit 1131207 by guisson: Fix memory leak in plasma dataengine BUG: 238948 M +1 -0 ChangeLog M +2 -0 plasma/dataengine/torrentdbusinterface.cpp WebSVN link: http://websvn.kde.org/?view=rev&revision=1131207
Thanks for the quick response! I don't know if this happens in practice, but the decode() method can return NULL or throw an exception, so it might be necessary to add a NULL check before the delete, as well as before the first time the return value is dereferenced (the line following decode()).
Scratch that first option - delete NULL is guaranteed to do nothing. The dereference might be a problem though (but is unrelated to the memory leak).
Yeah I need to add a check for that.