After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 523023 - Leaking EFolderExchange instances
Leaking EFolderExchange instances
Status: RESOLVED FIXED
Product: Evolution Exchange
Classification: Deprecated
Component: Connector
2.22.x
Other Linux
: Normal blocker
: ---
Assigned To: Bharath Acharya
Evolution QA team
Depends on:
Blocks:
 
 
Reported: 2008-03-17 18:18 UTC by Matthew Barnes
Modified: 2008-05-14 04:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Partial valgrind log for evolution-exchange-storage (135.00 KB, text/x-log)
2008-03-17 18:32 UTC, Matthew Barnes
  Details
Partial valgrind log for evolution-exchange-storage (151.14 KB, text/plain)
2008-03-19 16:27 UTC, Matthew Barnes
  Details
Proposed patch (1.38 KB, patch)
2008-03-19 18:25 UTC, Matthew Barnes
committed Details | Review
Followup patch (566 bytes, patch)
2008-04-18 16:28 UTC, Matthew Barnes
committed Details | Review

Description Matthew Barnes 2008-03-17 18:18:19 UTC
Evolution is leaking EFolderExchange instances like crazy.

Steps to Reproduce:

1) Build GLib with debugging enabled (--enable-debug).
2) $ GOBJECT_DEBUG=objects evolution 2>&1 | grep EFolder
3) In Evolution, configure an Exchange account.
4) Make sure the account works and you can see mail folders.
5) Exit Evolution and look for GObject messages on the terminal.

For me, simply starting and quitting Evolution with some dummy Exchange account that I don't really use shows 22 stale EFolderExchange instances.

  GLib-GObject-Message: [0x88ccfc0] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd050] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd098] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd100] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd130] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd160] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd190] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd1c0] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd220] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd250] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd280] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd2b0] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd300] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd330] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x883b5b0] stale EFolderExchange ref_count=3
  GLib-GObject-Message: [0x88cd360] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x883b600] stale EFolderExchange ref_count=5
  GLib-GObject-Message: [0x88cd390] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x88cd3c0] stale EFolderExchange ref_count=6
  GLib-GObject-Message: [0x883b690] stale EFolderExchange ref_count=5
  GLib-GObject-Message: [0x883b738] stale EFolderExchange ref_count=4
  GLib-GObject-Message: [0x88ccf60] stale EFolderExchange ref_count=6

Those who actually use Exchange are likely seeing more severe leakage.
Comment 1 Matthew Barnes 2008-03-17 18:32:23 UTC
Created attachment 107470 [details]
Partial valgrind log for evolution-exchange-storage

Here's the memory leak portion of a valgrind log showing data within EFolder instances leaking in an evolution-exchange-storage process.

The log was generated from a 1 hour run of Evolution 2.8, but I confirmed the EFolder leaks still exist on Evolution 2.22.  I'm trying to get logs for longer runs (day+) that show more severe memory consumption over time.
Comment 2 Akhil Laddha 2008-03-18 03:39:40 UTC
Matt, I have also filed a bug 517818 about memory leak in exchange connector during 2.21.x. 
Comment 3 Matthew Barnes 2008-03-18 04:13:21 UTC
Thanks Akhil.
Comment 4 Matthew Barnes 2008-03-19 16:27:56 UTC
Created attachment 107630 [details]
Partial valgrind log for evolution-exchange-storage

Here's another memcheck log from the same user, this time for a 3 hour run.

It shows EFolder objects consuming over 60MB of memory at exit, up from 20MB in the previous log.
Comment 5 Matthew Barnes 2008-03-19 17:42:50 UTC
I think I'm on to it.  Each memcheck log shows the unfreed EFolder allocations originating from exchange_hierarchy_webdav_parse_folder().

I think I found a problem in scan_subtree() (in exchange-hierarchy-webdav.c), which calls the "parse_folder" function that creates the leaking EFolders.


Relevant ChangeLog entry:

2006-02-25  Sushma Rai  <rsushma@novell.com>

        * storage/exchange-hierarchy-webdav.c (scan_subtree): Do not unref the
        folder which is being used later in subtrees.

Revision:
http://svn.gnome.org/viewvc/evolution-data-server/trunk/servers/exchange/storage/exchange-hierarchy-webdav.c?view=diff&r1=6811&r2=6812


That change was correct but it caused a side-effect, because now the folder /never/ gets unreffed.  And in a production environment you'll allocate a crapload of these instances in a single scan.

That explains why the leak is growing over time.
Comment 6 Matthew Barnes 2008-03-19 18:25:31 UTC
Created attachment 107642 [details] [review]
Proposed patch

I think this should do it.  Seems stable and valgrind confirms the leak is plugged.  Need someone more familiar with evolution-exchange to confirm it.
Comment 7 Bharath Acharya 2008-03-20 04:01:26 UTC
I can confirm that your patch will make sure to unref all the instances sanely.
Comment 8 Matthew Barnes 2008-03-24 14:57:48 UTC
Committed to trunk (revision 8579) and gnome-2-22 (revision 8580).
Comment 9 Matthew Barnes 2008-04-18 16:27:33 UTC
Reopening.  The above patch is correct, but Milan and I believe it may have uncovered a second, more serious reference counting error.

Index: storage/exchange-storage.c
===================================================================
--- storage/exchange-storage.c  (revision 1619)
+++ storage/exchange-storage.c  (working copy)
@@ -129,7 +129,7 @@ account_new_folder (ExchangeAccount *acc
 {
        const char *path = e_folder_exchange_get_path (folder);

-       e_storage_new_folder (storage, path, folder);
+       e_storage_new_folder (storage, path, g_object_ref (folder));
        if (e_folder_exchange_get_has_subfolders (folder)) {
                e_storage_declare_has_subfolders (storage, path,
                                                  _("Searching..."));

I could use a third pair of eyes on this before we ship 2.23.1.  Setting severity to BLOCKER.
Comment 10 Matthew Barnes 2008-04-18 16:28:40 UTC
Created attachment 109495 [details] [review]
Followup patch

Same as above.
Comment 11 Srinivasa Ragavan 2008-04-30 05:43:01 UTC
Bharath, can you review it for GNOME 2.22.x/2.24
Comment 12 Bharath Acharya 2008-05-06 10:33:10 UTC
Sorry was swamped with many things. Patch looks fine. Tested and works good. Please commit.
Comment 13 Bharath Acharya 2008-05-14 04:04:38 UTC
Committed to trunk (revision 1658) and gnome-2-22 (revision 1657). Thanks for the fix Matthew.