tracker r1700 - in branches/indexer-split: . src/libtracker-common



Author: mr
Date: Tue Jun 17 14:16:42 2008
New Revision: 1700
URL: http://svn.gnome.org/viewvc/tracker?rev=1700&view=rev

Log:
	* src/libtracker-common/tracker-dbus.c: Improved the
	tracker_dbus_async_queue_to_strv() function so it doesn't crash
	when handling large numbers of files.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker-common/tracker-dbus.c

Modified: branches/indexer-split/src/libtracker-common/tracker-dbus.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-dbus.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-dbus.c	Tue Jun 17 14:16:42 2008
@@ -90,10 +90,13 @@
 				  gint         max)
 {
 	gchar **strv;
-	gint    i = 0;
+	gchar  *str;
+	gint    i, j;
 	gint    length;
 
-	length = g_async_queue_length (queue);
+	g_async_queue_lock (queue);
+
+	length = g_async_queue_length_unlocked (queue);
 		
 	if (max > 0) {
 		length = MIN (max, length);
@@ -101,26 +104,25 @@
 
 	strv = g_new0 (gchar*, length + 1);
 	
-	while (i <= length) {
-		gchar *str;
-		
-		str = g_async_queue_try_pop (queue);
+	for (i = 0, j = 0; i < length; i++) {
+		str = g_async_queue_try_pop_unlocked (queue);
 
-		if (str) {
-			if (!g_utf8_validate (str, -1, NULL)) {
-				g_message ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
-				g_free (str);
-				continue;
-			}
-
-			strv[i++] = str;
-		} else {
-			/* Queue is empty and we don't expect this */
+		if (!str) {
 			break;
 		}
+
+		if (!g_utf8_validate (str, -1, NULL)) {
+			g_message ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
+			g_free (str);
+			continue;
+		}
+
+		strv[j++] = str;
 	}
 
-        strv[i] = NULL;
+        strv[j] = NULL;
+
+	g_async_queue_unlock (queue);
 
 	return strv;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]