DarKtears

or Alexis Menard in the real world.

The “plasma leak” story…

10 Comments

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

Author: darktears

Software Engineer at Intel Corporation.

10 thoughts on “The “plasma leak” story…

  1. Beautiful story 😉 Great work!

  2. Can we have a Krazy check for this kind of stuff ?

  3. I like detective stories and stories with a happy ending 🙂

  4. True heroes :p

  5. Will those fixes make it into kde 4.3 final?

  6. @kriko : in KDE 4.3 final.

    @pvandewyngaerde : no, the problem doesn’t show up with valgrind, it needs manual investigation. It is not by just a static test of the code.

  7. oh, we all soo love the X sysem tray :p

  8. Hmm… the code fixes the actual problem, but not the underlying issue: Resources are not properly managed. This bug will be back again, I fear. Can’ we use RAII or a reference count to make returning a no-brainer?

    • What do you mean by resources not properly managed? I am pretty curious to know. Reference count is already present in QPixmap but in X you don’t have such of thing so unless X is improved we can’t do anything about it. That’s why we don’t recommend to use X directly (or CoreGraphics or Windows painting stack) but Qt that provide you those features. In that case the systray is a hack because of an old legacy and need to use X for some reason. I don’t see how we can do better here but i am open to any suggestions.

  9. Thank God!!!! I thought I was crazy… I thought it was an interaction of GTK apps or VMWare! It was the seconds…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s