--- libopensync/opensync/xmlformat/opensync_xmlfield.c.orig	2010-01-05 18:44:06.561461611 +0100
+++ libopensync/opensync/xmlformat/opensync_xmlfield.c	2010-01-23 18:29:04.325231178 +0100
@@ -570,8 +570,12 @@ osync_bool osync_xmlfield_sort(OSyncXMLF
 	
 	for(index = 0; index < count; index++) {
 		cur = (xmlNodePtr)list[index];
-		xmlAddChild(xmlfield->node, cur);
-			
+		list[index] = cur = xmlAddChild(xmlfield->node, cur);
+		if (cur == NULL) {
+			osync_error_set(error, OSYNC_ERROR_GENERIC, "xmlAddChild() has failed.");	
+			goto error;
+		}
+	
 		if(index < count-1)
 			cur->next = (xmlNodePtr)list[index+1];
 		else

