(I actually found the bugs a few days ago, but only just got round to blogging about it)
A couple of days ago, I was reviewing a patch and came across a function call to an interface of the type:
void foo(out unsigned long aCount, [array, size_is(count)] out bar aResult);
Where bar was an object derived from nsISupports. The aResult was being freed with NS_Free, instead of NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY. This would have ended up with MailNews leaking most of the objects in the array.
Being curious about where this came from, I did a quick search for the function, and found one instance already in the main code base, where we called NS_Free instead of the NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY. It wasn’t a major leak and would only happen on migration of some of the tag preferences, and for most users would probably end up being 300 bytes. However bug 431404 was raised, and that will soon be checked in.
Having realised that at least one instance in MailNews did this wrong, I did a quick audit of the other function calls in MailNews that obtain an array in the style above. A bit of searching later and I filed the patch on bug 431414, this fixes several leaks in migration, one potential leak in the LDAP autocomplete code, and two leaks related to getting/receiving mail.
The leaks I found when getting/receiving mail, really are small, effectively 4 or 8 bytes per message or newsgroup post, so you probably won’t notice too much difference. These also won’t show up on the Leak stats as we don’t currently receive messages in those tests (that is one of the things I want to extend those tests to do).
Improving MailNews performance, reducing leaks, bloat etc, is something I really want to see happen, this is one small step along the road, and I’ll certainly be looking out for more instances where we do our memory management wrong.