[xml] Potential memory leek in xmlCreateMemoryParserCtxt



xmlParserCtxtPtr
xmlCreateMemoryParserCtxt(const char *buffer, int size) {
    xmlParserCtxtPtr ctxt;
    xmlParserInputPtr input;
    xmlParserInputBufferPtr buf;

    if (buffer == NULL)
        return(NULL);
    if (size <= 0)
        return(NULL);

    ctxt = xmlNewParserCtxt();
    if (ctxt == NULL)
        return(NULL);

    buf = xmlParserInputBufferCreateMem(buffer, size,
XML_CHAR_ENCODING_NONE);
    if (buf == NULL) return(NULL); /* <-------------- potential leek */

    input = xmlNewInputStream(ctxt);
    if (input == NULL) {
        xmlFreeParserCtxt(ctxt);
        return(NULL);
    }

    input->filename = NULL;
    input->buf = buf;
    input->base = input->buf->buffer->content;
    input->cur = input->buf->buffer->content;
    input->end = &input->buf->buffer->content[input->buf->buffer->use];

    inputPush(ctxt, input);
    return(ctxt);
}


I believe the line:
    if (buf == NULL) return(NULL);

should look like:
    if (buf == NULL) {
        xmlFreeParserCtxt(ctxt);
        return(NULL);
    }





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