[xml] Memory leak with xmlFindCharEncodingHandler



Hi, list.

I have memory leak problem in one software product which uses libxml2.

There is following code in this project:

    handler = xmlFindCharEncodingHandler(charset);
    if (handler == NULL)
        return -2;

    /* Build the libxml buffers for the transcoding. */
    tobuffer = xmlBufferCreate();
    frombuffer = xmlBufferCreate();
    xmlBufferAdd(frombuffer, from, strlen(from));

    ret = xmlCharEncInFunc(handler, tobuffer, frombuffer);

    /* Memory cleanup. */
    xmlBufferFree(tobuffer);
    xmlBufferFree(frombuffer);

    return ret;

Problem is that in case when handler for charset is not registred, than
iconv handler will be allocated in libxml2, but doesn't freed by this code.
On other side we can't free any handler because in can be one from registred
handlers.

How I can solve this problem? Is there documented way how to know is this
handler was allocated or got from registred handlers?

--
Vjacheslav Chekushin                                mailto:sck lmt lv
Latvian Mobile Phone Company                        http://www.lmt.lv
VAS Technologies Division                           +371 7773436
                                                    +371 9248284 (mobile)




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