CESNET / libnetconf

C NETCONF library
Other
113 stars 84 forks source link

Question about edit_merge_lists() #168

Closed classcwnd closed 8 years ago

classcwnd commented 8 years ago

Hi,

I think following code in edit_merge_list() has problem. merge_code shall be added directly without xmlCopyNode(), otherwise there shall be memory leak, because merge_code is not released at all.

if (refnode != NULL) {
    /* relink th node before the currently first instance of the list */
    xmlAddPrevSibling(refnode, xmlCopyNode(merged_node, 1));
} else {
    /* re-link the node as last node since there is currently no instance of the list */
    xmlAddChild(parent, xmlCopyNode(merged_node, 1));
}

shall be

if (refnode != NULL) {
    /* relink th node before the currently first instance of the list */
    xmlAddPrevSibling(refnode, merged_node);
} else {
    /* re-link the node as last node since there is currently no instance of the list */
    xmlAddChild(parent, merged_node);
}
rkrejci commented 8 years ago

Hi, do you have an example data causing memory leak?

rkrejci commented 8 years ago

I was able to reproduce it, you are right.