[xml] non-unique attr handling in xmlAddChild()



Hi folks,

I belive, that the handling of Attributes given to xmlAddChild is wrong in case an attribute with the same name already exists at the parent node [1].

When a property (attribute) with the same name is found, it is freed and the new prop node is appended to the end of the property list. If I understand matters correctly, the old property is just freed from wherever it was in the prop list, leving it's peers with dangling references to the old property. Since the new prop is appended to the end, this would only work if the property with the same name was found right at the end of the list.

I think that either a call to xmlRemoveProp(... lastattr) or the transfer of cur's content to lastprop, freeing cur and stting cur=lastprop for return would be the way to go. I belive the latter approach would be better, since it would leave other references to lastprop intact.

Or am I just missing something?

Bests,
~Lars

[1]: tree.c:3278
if (cur->type == XML_ATTRIBUTE_NODE) {
if (parent->properties == NULL) {
    parent->properties = (xmlAttrPtr) cur;
} else {
    /* check if an attribute with the same name exists */
    xmlAttrPtr lastattr;

    if (cur->ns == NULL)
        lastattr = xmlHasProp(parent, cur->name);
    else
        lastattr = xmlHasNsProp(parent, cur->name, cur->ns->href);
    if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur)) {
        /* different instance, destroy it (attributes must be unique) */
        xmlFreeProp(lastattr);
    }
    /* find the end */
    lastattr = parent->properties;
    while (lastattr->next != NULL) {
        lastattr = lastattr->next;
    }
    lastattr->next = (xmlAttrPtr) cur;
    ((xmlAttrPtr) cur)->prev = lastattr;
}
}




--
Lars Oppermann <lars oppermann sun com>               Sun Microsystems
Software Engineer - StarOffice                           Sachsenfeld 4
Phone: +49 40 23646 959                                D-20097 Hamburg
Fax:   +49 40 23646 550                  http://www.sun.com/staroffice



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