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/EvolutionSyncSource.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/backends/evolution/EvolutionSyncSource.cpp') diff --git a/src/backends/evolution/EvolutionSyncSource.cpp b/src/backends/evolution/EvolutionSyncSource.cpp index e39a5302..f569082b 100644 --- a/src/backends/evolution/EvolutionSyncSource.cpp +++ b/src/backends/evolution/EvolutionSyncSource.cpp @@ -36,7 +36,7 @@ void EvolutionSyncSource::getDatabasesFromRegistry(SyncSource::Databases &result ESourceRegistryCXX registry = EDSRegistryLoader::getESourceRegistry(); ESourceListCXX sources(e_source_registry_list_sources(registry, extension)); ESourceCXX def(refDef ? refDef(registry) : NULL, - false); + TRANSFER_REF); BOOST_FOREACH (ESource *source, sources) { result.push_back(Database(e_source_get_display_name(source), e_source_get_uid(source), @@ -64,7 +64,7 @@ EClientCXX EvolutionSyncSource::openESource(const char *extension, if (!source) { if (refBuiltin && (id.empty() || id == "<>")) { - ESourceCXX builtin(refBuiltin(registry), false); + ESourceCXX builtin(refBuiltin(registry), TRANSFER_REF); client = EClientCXX::steal(newClient(builtin, gerror)); // } else if (!id.compare(0, 7, "file://")) { // TODO: create source @@ -129,7 +129,7 @@ SyncSource::Database EvolutionSyncSource::createDatabase(const Database &databas e_source_new(NULL, NULL, gerror) : e_source_new_with_uid(database.m_uri.c_str(), NULL, gerror), - false); + TRANSFER_REF); if (!source) { gerror.throwError("e_source_new()"); } @@ -179,7 +179,7 @@ SyncSource::Database EvolutionSyncSource::createDatabase(const Database &databas void EvolutionSyncSource::deleteDatabase(const std::string &uri) { ESourceRegistryCXX registry = EDSRegistryLoader::getESourceRegistry(); - ESourceCXX source(e_source_registry_ref_source(registry, uri.c_str()), false); + ESourceCXX source(e_source_registry_ref_source(registry, uri.c_str()), TRANSFER_REF); if (!source) { throwError(StringPrintf("EDS database with URI '%s' cannot be deleted, does not exist", uri.c_str())); -- cgit v1.2.3