senojsitruc / wsdl2objc

Automatically exported from code.google.com/p/wsdl2objc
MIT License
0 stars 0 forks source link

XMLMutex Leak in serializedFormUsingHeaderElements... #43

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output?
Parses XML without memory leaks.
What do you see instead?
In leaks when running with the device, I get this leak reported with a size of 
48 bytes.

What version of the product are you using? On what operating system?
.6

Please provide any additional information below.
I'm not very familiar with libxml2 so I can not suggest a fix.   The method is 
listed below and the 
line that reports the leak is marked with --.
This is the method:
- (NSString *)serializedFormUsingHeaderElements:(NSDictionary *)headerElements 
bodyElements:(NSDictionary *)bodyElements
{
    xmlDocPtr doc;

    doc = xmlNewDoc((const xmlChar*)XML_DEFAULT_VERSION);
    if (doc == NULL) {
        NSLog(@"Error creating the xml document tree");
        return @"";
    }

    xmlNodePtr root = xmlNewDocNode(doc, NULL, (const xmlChar*)"Envelope", NULL);
    xmlDocSetRootElement(doc, root);

    xmlNsPtr soapEnvelopeNs = xmlNewNs(root, (const 
xmlChar*)"http://schemas.xmlsoap.org/soap/envelope/", (const xmlChar*)"soap");
    xmlSetNs(root, soapEnvelopeNs);

    xmlNsPtr xslNs = xmlNewNs(root, (const 
xmlChar*)"http://www.w3.org/1999/XSL/Transform", (const xmlChar*)"xsl");
    xmlNewNs(root, (const xmlChar*)"http://www.w3.org/2001/XMLSchema-instance", (const 
xmlChar*)"xsi");

    xmlNewNsProp(root, xslNs, (const xmlChar*)"version", (const xmlChar*)"1.0");

    xmlNewNs(root, (const xmlChar*)"http://www.w3.org/2001/XMLSchema", (const 
xmlChar*)"xsd");
    xmlNewNs(root, (const xmlChar*)"http://www.wso2.org/php", (const 
xmlChar*)"AlertService-1_0");
    xmlNewNs(root, (const xmlChar*)"http://www.wso2.org/php/xsd", (const xmlChar*)"ns3");

    if((headerElements != nil) && ([headerElements count] > 0)) {
        xmlNodePtr headerNode = xmlNewDocNode(doc, soapEnvelopeNs, (const 
xmlChar*)"Header", NULL);
        xmlAddChild(root, headerNode);

        for(NSString *key in [headerElements allKeys]) {
            id header = [headerElements objectForKey:key];
            xmlAddChild(headerNode, [header xmlNodeForDoc:doc elementName:key]);
        }
    }

    if((bodyElements != nil) && ([bodyElements count] > 0)) {
        xmlNodePtr bodyNode = xmlNewDocNode(doc, soapEnvelopeNs, (const 
xmlChar*)"Body", NULL);
        xmlAddChild(root, bodyNode);

        for(NSString *key in [bodyElements allKeys]) {
            id body = [bodyElements objectForKey:key];
            xmlAddChild(bodyNode, [body xmlNodeForDoc:doc elementName:key]);
        }
    }

    xmlChar *buf;
    int size;
--This Line leaks - Malloc 48 Bytes
    xmlDocDumpFormatMemory(doc, &buf, &size, 1);
--

    NSString *serializedForm = [NSString stringWithCString:(const char*)buf 
encoding:NSUTF8StringEncoding];
    xmlFree(buf);

    xmlFreeDoc(doc);    
    return serializedForm;
}

Original issue reported on code.google.com by mr.coo...@gmail.com on 9 Oct 2009 at 7:25