{"id":11,"date":"2008-05-02T08:16:35","date_gmt":"2008-05-02T08:16:35","guid":{"rendered":"http:\/\/ccgi.standard8.plus.com\/blog\/archives\/11"},"modified":"2017-08-15T22:19:40","modified_gmt":"2017-08-15T21:19:40","slug":"soon-to-be-a-few-less-minor-mailnews-memory-leaks","status":"publish","type":"post","link":"https:\/\/thebanners.uk\/standard8\/2008\/05\/02\/soon-to-be-a-few-less-minor-mailnews-memory-leaks\/","title":{"rendered":"Soon to be a few less (minor) MailNews Memory Leaks"},"content":{"rendered":"<p>(I actually found the bugs a few days ago, but only just got round to blogging about it)<\/p>\n<p>A couple of days ago, I was reviewing a patch and came across a function call to an interface of the type:<\/p>\n<p><code>void foo(out unsigned long aCount, [array, size_is(count)] out bar aResult);<\/code><\/p>\n<p>Where <code>bar<\/code> was an object derived from <code>nsISupports<\/code>. The <code>aResult<\/code> was being freed with <code>NS_Free<\/code>, instead of <code>NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY<\/code>. This would have ended up with MailNews leaking most of the objects in the array.<\/p>\n<p>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 <code>NS_Free<\/code> instead of the <code>NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY<\/code>. It wasn&#8217;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 <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=431404\" title=\"Memory leak (n * 60 bytes) when tags are migrated from version 1 to 2\">bug 431404<\/a> was raised, and that will soon be checked in.<\/p>\n<p>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 <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=431414\" title=\"Review MailNews uses of idl functions that return xpcom allocated arrays [..., array, ...] for memory leaks\">bug 431414<\/a>, this fixes several leaks in migration, one potential leak in the LDAP autocomplete code, and two leaks related to getting\/receiving mail.<\/p>\n<p>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&#8217;t notice too much difference. These also won&#8217;t show up on the <a href=\"http:\/\/wiki.mozilla.org\/MailNews:Memory_Bloat_and_Leak_Tests\" title=\"MailNews Memory Bloat and Leak Stats wiki page\">Leak stats<\/a> as we don&#8217;t currently receive messages in those tests (that is one of the things I want to extend those tests to do).<\/p>\n<p>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&#8217;ll certainly be looking out for more instances where we do our memory management wrong.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(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 &hellip; <a href=\"https:\/\/thebanners.uk\/standard8\/2008\/05\/02\/soon-to-be-a-few-less-minor-mailnews-memory-leaks\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Soon to be a few less (minor) MailNews Memory Leaks&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7,8],"tags":[],"class_list":["post-11","post","type-post","status-publish","format-standard","hentry","category-mozilla","category-seamonkey","category-thunderbird"],"_links":{"self":[{"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":1,"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/posts\/11\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thebanners.uk\/standard8\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}