Fix memory leak on ConnectionManagerTest.
ConnectionManagerTest::SetServiceReply had a memory leak only present
on unittest code. This patch uses g_new0() and g_free() to manage the
memory of GValue objects on GValueNewString and GValueFree, which
allows to use GValueFree to remove any GValue object.
It also replaces the GArray* by a GPtrArray which is what dbus-glib
uses and what is being passed as the GType, as defined on the
DBusWrapperInterface.
BUG=chromium:378548
TEST=`FEATURES="test" USE="clang asan" emerge-link update_engine` doesn't show ConnectionManager failures
TEST=tested on link the update_engine detects the current connection from shill.
Change-Id: I328ba79e2d609ab1cfe3df8b99b82fa24262de08
Reviewed-on: https://chromium-review.googlesource.com/202060
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/connection_manager.cc b/connection_manager.cc
index 45c971a..9e3ac1e 100644
--- a/connection_manager.cc
+++ b/connection_manager.cc
@@ -84,12 +84,12 @@
GValue* value = reinterpret_cast<GValue*>(g_hash_table_lookup(hash_table,
"Services"));
- GArray* array = NULL;
+ GPtrArray* array = NULL;
bool success = false;
if (G_VALUE_HOLDS(value, DBUS_TYPE_G_OBJECT_PATH_ARRAY) &&
- (array = reinterpret_cast<GArray*>(g_value_get_boxed(value))) &&
+ (array = reinterpret_cast<GPtrArray*>(g_value_get_boxed(value))) &&
(array->len > 0)) {
- *out_path = g_array_index(array, const char*, 0);
+ *out_path = static_cast<const char*>(g_ptr_array_index(array, 0));
success = true;
}