void osync_xmlfield_delete(OSyncXMLField *xmlfield) { OSyncXMLField *child = NULL; osync_assert(xmlfield); // unlink and free our children first // // if we unlink ourselves (and therefore all the children) // then osync_xmlfield_free() will leak, since it doesn't know children // // if we code free to know children, then, as it cycles through the // OSyncXMLField children, it won't know how to tell whether each // child's node needs to be freed, or whether it has been freed // at the top level node. // // really, it's just easier and safer with this inefficient method :-( // I tried doing it in _free() and couldn't get it to work well. - CDF // for (child = xmlfield->child; child; ) { OSyncXMLField *next = child->next; osync_xmlfield_unlink(child); osync_xmlfield_free(child); child = next; } osync_xmlfield_unlink(xmlfield); osync_xmlfield_free(xmlfield); }
void osync_xmlfield_delete(OSyncXMLField *xmlfield) { osync_assert(xmlfield); osync_xmlfield_unlink(xmlfield); osync_xmlfield_free(xmlfield); }
osync_bool osync_xmlfield_parse(OSyncXMLField *parent, xmlNodePtr node, OSyncXMLField **first_child, OSyncXMLField **last_child, OSyncError **error) { OSyncXMLField *xmlfield = NULL; if (first_child) *first_child = NULL; while (node != NULL) { /* TODO: error handing - could be NULL */ xmlfield = osync_xmlfield_new_xmlfield(parent, node, error); if (!xmlfield) goto error; if (first_child && !(*first_child)) { *first_child = xmlfield; } if (node->children && node->children->type == XML_ELEMENT_NODE) if (!osync_xmlfield_parse(xmlfield, node->children, NULL, NULL, error)) goto error_and_free; node = node->next; } if (last_child) *last_child = xmlfield; return TRUE; error_and_free: osync_xmlfield_free(xmlfield); error: if (last_child) *last_child = NULL; if (first_child) *first_child = NULL; osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error)); return FALSE; }