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/EvolutionCalendarSource.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/backends/evolution/EvolutionCalendarSource.cpp') diff --git a/src/backends/evolution/EvolutionCalendarSource.cpp b/src/backends/evolution/EvolutionCalendarSource.cpp index f9cdf1f3..cb01eb44 100644 --- a/src/backends/evolution/EvolutionCalendarSource.cpp +++ b/src/backends/evolution/EvolutionCalendarSource.cpp @@ -156,7 +156,7 @@ SyncSource::Databases EvolutionCalendarSource::getDatabases() throwError("unable to access backend databases", gerror); } } - ESourceListCXX sources(tmp, false); + ESourceListCXX sources(tmp, TRANSFER_REF); bool first = true; for (GSList *g = sources ? e_source_list_peek_groups (sources) : NULL; g; @@ -240,7 +240,7 @@ void EvolutionCalendarSource::open() if (!e_cal_get_sources(&tmp, sourceType(), gerror)) { throwError("unable to access backend databases", gerror); } - ESourceListCXX sources(tmp, false); + ESourceListCXX sources(tmp, TRANSFER_REF); string id = getDatabaseID(); ESource *source = findSource(sources, id); @@ -430,7 +430,7 @@ void EvolutionCalendarSource::listAllItems(RevisionMap_t &revisions) void EvolutionCalendarSource::close() { - m_calendar = NULL; + m_calendar.reset(); } void EvolutionCalendarSource::readItem(const string &luid, std::string &item, bool raw) @@ -858,7 +858,7 @@ void EvolutionCalendarSource::removeItem(const string &luid) * remove all items with the given uid and if we only wanted to * delete the parent, then recreate the children. */ - ICalComps_t children = removeEvents(id.m_uid, true, false); + ICalComps_t children = removeEvents(id.m_uid, true, TRANSFER_REF); // recreate children bool first = true; -- cgit v1.2.3