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. --- test/dbus-client-server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/dbus-client-server.cpp b/test/dbus-client-server.cpp index 6bef63dd..60fd6514 100644 --- a/test/dbus-client-server.cpp +++ b/test/dbus-client-server.cpp @@ -273,7 +273,7 @@ int main(int argc, char **argv) // throw stdruntime_error("The --allow-anonymous option only makes sense when used with --server."); // } - loop = SyncEvo::GMainLoopCXX(g_main_loop_new (NULL, FALSE), false); + loop = SyncEvo::GMainLoopStealCXX(g_main_loop_new (NULL, FALSE)); if (!loop) { throw std::runtime_error("could not allocate main loop"); } -- cgit v1.2.3