DarKtears

or Alexis Menard in the real world.


10 Comments

The “plasma leak” story…

I think i can say that this story is finally ended!!!
Let me now tell the full story :

Once upon a time in the plasma world…..oops… No seriously, i was poked couple of weeks ago by Aseigo about a possible leak in Qt. The leak show up when you trigger “display seconds” on the digital-clock, xrestop was showing plasma allocating XPixmaps like a hell and after some point stop rendering texts/pixmaps properly and crash. So why? Aseigo kindly investigate and found a possible leak in QGraphicsView code base. In fact, it was one level below in QPixmapCache. The issue was when you insert a new QPixmap with an already used key then the old QPixmap associated to that key was not properly deleted (aie aie aie). The commit in Qt is here : http://qt.gitorious.org/qt/qt/commit/ae949b9d21470a9b9bf200774c246a0b86a69ff6

At that time, i was working on an extension of QPixmapCache in order for it to handle non string based key (speedup++). So i tried the same test case with the new implementation and booom same error but this time it was in the way we’re using the new API in QGraphicsView (just a wrong piece of code herited from the old string key legacy). With the new implementation QGV has been fixed and this bug will never see the “light”. The commit is in Qt main : http://qt.gitorious.org/qt/qt/commit/87911c6c97b11bd7d10a38698460174b6cadfbe8.

But then the story was still not finished, if plasma was running several days then still it was leaking XPixmaps. Grrrrr. Since valgrind can’t help you in that case then you have to investigate manually. I basically tried everything with the QPixmapCache (both new and old) to be sure it was not leaking. I double checked reference counting in QPixmap to be sure QPixmapData’s was correctly deleted, everything was working as expected. With samuel (a troll), we decided to create a static hash map of QString, int in QPixmapData which will contain as a key the backtrace of callers (using kRealBacktrace) and the number of time the caller tries to allocate QPixmapData. Nothing bad show up.

Finally i had a break and before i started to be crazy, i thought : “What is running in Plasma (and triggers updates) when i leave the office?”. The answer is, the clock (again) and the systray (Konversation blinking and KMail showing my mails). And the solution was in the last guy, the systray applet. This applet creates XPixmap and never release them in some cases. Here is the log :
http://websvn.kde.org/trunk/KDE/kdebase/workspace/plasma/applets/systemtray/protocols/fdo/x11embedcontainer.cpp?view=log

It has been fixed now and plasma show only 200 pixmaps in xrestop when idle.

End.

Thanks for people involved in that bug (both reporters, KDE developers and Qt developers).

Advertisements