Comment 14 for bug 725435

Revision history for this message
nh2 (nh2) wrote :

I think I have the solution.

First an explanation of the above quitting logic: The "bubble IDs" count upwards from 1, one for each notification bubble shown. When the bubble ID reaches FORCED_SHUTDOWN_THRESHOLD = 500, then _arm_forced_quit() is called, which quits the process using gtk_main_quit() and thus terminates notify-osd, and it is restarted automatically (I think by DBUS) when the next notification comes in.

So the first bubble ID is 1, the second 2, and so on.
You can verify that e.g. by inserting

 printf("bubble ID %u\n", bubble_get_id (bubble));

But this is only the case if you wait between your `notify-send mytext` invocations until the current bubble has faded out and is no longer shown.
If you call `notify-send mytext` while the previous notification is still being displayed then bubble ID is actually 0.
(This is because the variable `bubble` is NULL in that case, and bubble_get_id(NULL) returns 0.)
But the bubble ID generation counter is still incremented nevertheless.
So if your generated bubble IDs are 1, 2, and then 0, the next bubble ID generated will be 4.

You can generate this situation e.g. this way (note that the default notification timeout is 10 seconds, so I sleep 11 seconds):

    notify-send test && sleep 11 && notify-send test && notify-send test && sleep 11 && notify-send test

So when you send notifications in quick succession, their bubble IDs are skipped.

Now, if you send them in quick succession around the 500th notification, then the check

  if (bubble_get_id (bubble) == FORCED_SHUTDOWN_THRESHOLD)

will never trigger (e.g. because the bubble IDs will be 499, 0, and 501).

Then the forced shutdown will never happen, and notify-osd will leak memory forever instead of being restarted every 500th notification.

The fix is to use

  if (bubble_get_id (bubble) >= FORCED_SHUTDOWN_THRESHOLD)

instead.