From d3eee8a0390558795ace8be503b44d76be385b13 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 13 May 2013 21:33:34 +0200 Subject: glib: stricter ref counting Following the boost::instrusive_ptr example and making "add_ref = true" the default in our CXX GLib and GObject wrappers led to some memory leaks because it didn't enforce thinking about whether the plain pointer is already owned by us or not. It is better to use a mandatory enum value, ADD_REF and TRANSFER_REF, and force explicit construction. Doing that revealed that the assignment operator was implemented as constructing a CXX instance with increased ref count and/or that in some places, a real leak was caused by increasing the ref count unnecessarily. Running under valgrind gave a false sense of security. Some of the real leaks only showed up randomly in tests. --- src/backends/evolution/EvolutionContactSource.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/backends/evolution/EvolutionContactSource.cpp') diff --git a/src/backends/evolution/EvolutionContactSource.cpp b/src/backends/evolution/EvolutionContactSource.cpp index 05821055..ea23d615 100644 --- a/src/backends/evolution/EvolutionContactSource.cpp +++ b/src/backends/evolution/EvolutionContactSource.cpp @@ -177,7 +177,7 @@ void EvolutionContactSource::open() if (!e_book_get_addressbooks(&tmp, gerror)) { throwError("unable to access address books", gerror); } - ESourceListCXX sources(tmp, false); + ESourceListCXX sources(tmp, TRANSFER_REF); string id = getDatabaseID(); ESource *source = findSource(sources, id); @@ -347,7 +347,7 @@ void EvolutionContactSource::listAllItems(RevisionMap_t &revisions) GErrorCXX gerror; EBookClientView *view; - EBookQueryCXX allItemsQuery(e_book_query_any_field_contains(""), false); + EBookQueryCXX allItemsQuery(e_book_query_any_field_contains(""), TRANSFER_REF); PlainGStr sexp(e_book_query_to_string (allItemsQuery.get())); if (!e_book_client_get_view_sync(m_addressbook, sexp, &view, NULL, gerror)) { @@ -403,7 +403,7 @@ void EvolutionContactSource::listAllItems(RevisionMap_t &revisions) void EvolutionContactSource::close() { - m_addressbook = NULL; + m_addressbook.reset(); } string EvolutionContactSource::getRevision(const string &luid) -- cgit v1.2.3