Menu

#10 Memory Leak Inserting New Nodes

open
nobody
None
5
2009-07-08
2009-07-08
No

A memory leak occurs when a new node is created with ezxml_new() and added to an existing document using ezxml_insert(). The root tag allocations don't get freed. In the attached test case, test.c should not leak but it does, as shown in the valgrind log file.

Discussion

  • Frank Pilhofer

    Frank Pilhofer - 2009-07-08

    ezxml-leak.zip

     
  • bash

    bash - 2011-07-26

    I found the same problem and, after few debug I solved in this way:
    --- ezxml.c (from version 0.8.6)
    +++ ezxml.c (local)
    @@ -808,7 +808,6 @@
    if (! xml->parent) { // free root tag allocations
    for (i = 10; root->ent[i]; i += 2) // 0 - 9 are default entites (<>&"')
    if ((s = root->ent[i + 1]) < root->s || s > root->e) free(s);
    - free(root->ent); // free list of general entities

    for (i = 0; (a = root->attr[i]); i++) {
    for (j = 1; a[j++]; j += 2) // free malloced attribute values
    @@ -831,6 +830,7 @@
    if (root->u) free(root->u); // utf8 conversion
    }

    + if( root->ent ) free(root->ent); // free list of general entities
    ezxml_free_attr(xml->attr); // tag attributes
    if ((xml->flags & EZXML_TXTM)) free(xml->txt); // character content
    if ((xml->flags & EZXML_NAMEM)) free(xml->name); // tag name

    I hope this could help!
    Bye

     

Log in to post a comment.

MongoDB Logo MongoDB