tracker r2041 - in branches/indexer-split: . src/libtracker-db tests/libtracker-db
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2041 - in branches/indexer-split: . src/libtracker-db tests/libtracker-db
- Date: Mon, 11 Aug 2008 14:19:55 +0000 (UTC)
Author: ifrade
Date: Mon Aug 11 14:19:54 2008
New Revision: 2041
URL: http://svn.gnome.org/viewvc/tracker?rev=2041&view=rev
Log:
Fixed memory leaks and handling null values in tracker_dbus_query_result_to_ptr_array
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/libtracker-db/tracker-db-dbus.c
branches/indexer-split/tests/libtracker-db/tracker-db-dbus-test.c
Modified: branches/indexer-split/src/libtracker-db/tracker-db-dbus.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-dbus.c (original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-dbus.c Mon Aug 11 14:19:54 2008
@@ -239,22 +239,24 @@
while (valid) {
GSList *list = NULL;
- GValue transform = { 0, };
gchar **p;
- g_value_init (&transform, G_TYPE_STRING);
-
/* Append fields to the array */
for (i = 0; i < columns; i++) {
+ GValue transform = { 0, };
GValue value = { 0, };
gchar *str;
+ g_value_init (&transform, G_TYPE_STRING);
+
_tracker_db_result_set_get_value (result_set, i, &value);
if (g_value_transform (&value, &transform)) {
str = g_value_dup_string (&transform);
- if (!g_utf8_validate (str, -1, NULL)) {
+ if (!str) {
+ str = g_strdup ("");
+ } else if (!g_utf8_validate (str, -1, NULL)) {
g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
g_free (str);
str = g_strdup ("");
@@ -266,12 +268,15 @@
list = g_slist_prepend (list, (gchar*) str);
g_value_unset (&value);
- g_value_reset (&transform);
+ g_value_unset (&transform);
}
-
+
list = g_slist_reverse (list);
p = tracker_dbus_slist_to_strv (list);
+
+ g_slist_foreach (list, (GFunc)g_free, NULL);
g_slist_free (list);
+
g_ptr_array_add (ptr_array, p);
valid = tracker_db_result_set_iter_next (result_set);
Modified: branches/indexer-split/tests/libtracker-db/tracker-db-dbus-test.c
==============================================================================
--- branches/indexer-split/tests/libtracker-db/tracker-db-dbus-test.c (original)
+++ branches/indexer-split/tests/libtracker-db/tracker-db-dbus-test.c Mon Aug 11 14:19:54 2008
@@ -38,10 +38,14 @@
for (j = 0; j < columns; j++) {
GValue value = {0,};
+ gchar * text = g_strdup_printf ("value %d", i);
g_value_init (&value, G_TYPE_STRING);
- g_value_set_string (&value, (set_null ? NULL : g_strdup_printf ("value %d", i)));
+ g_value_set_string (&value, (set_null ? NULL : text));
_tracker_db_result_set_set_value (mock, j, &value);
+
+ g_value_unset (&value);
+ g_free (text);
}
}
@@ -81,7 +85,7 @@
result = tracker_dbus_query_result_to_strv (result_set, 0, &count);
}
g_test_trap_assert_failed ();
- // Should raise g_critical (priv->array...);
+ /* Should raise g_critical (priv->array...); */
g_object_unref (result_set);
@@ -105,10 +109,51 @@
}
static void
+free_string_ptr_array (GPtrArray *array)
+{
+ g_ptr_array_foreach (array, (GFunc)g_strfreev, NULL);
+ g_ptr_array_free (array, TRUE);
+}
+
+static void
test_dbus_query_result_to_ptr_array ()
{
- /* TODO: Implement */
- g_print ("- Unimplemented -\n");
+ TrackerDBResultSet *result_set = NULL;
+ GPtrArray *result = NULL;
+ gint count;
+
+ /* NULL */
+ result = tracker_dbus_query_result_to_ptr_array (result_set);
+ g_assert_cmpint (result->len, ==, 0);
+ free_string_ptr_array (result);
+
+ /* 5 results, 1 column */
+ result_set = get_mock_tracker_db_result (5, 1, FALSE);
+ result = tracker_dbus_query_result_to_ptr_array (result_set);
+
+ g_assert_cmpint (result->len, ==, 5);
+ free_string_ptr_array (result);
+
+ g_object_unref (result_set);
+
+ /* 0 results, 1 columns */
+ result_set = get_mock_tracker_db_result (0, 1, FALSE);
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ result = tracker_dbus_query_result_to_ptr_array (result_set);
+ free_string_ptr_array (result);
+ }
+ g_test_trap_assert_failed ();
+ /* Should raise g_critical (priv->array...); */
+
+ g_object_unref (result_set);
+
+ /* 1 result ... NULL */
+ result_set = get_mock_tracker_db_result (1, 1, TRUE);
+ result = tracker_dbus_query_result_to_ptr_array (result_set);
+ g_assert_cmpint (result->len, ==, 1);
+ free_string_ptr_array (result);
+
+ g_object_unref (result_set);
}
gint
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]