You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Patrick Wicki <pa...@wsl.ch> on 2004/03/05 09:42:27 UTC

Memory-Release after using DOMNodeList*?

Hello,
Can anybody tell me, how to release a DOMNodeList*? Or do you happen to see 
what causes a memory leak in the function below!

Best regards
Pat

Following is the function, which seems to cause an error. My App crashes 
after using it about 200 times!

void sdeconn::get_sql_stat_from_xml(std::vector<CString>& tag)
{
	DOMNodeList* sql_statements;
	
	//Get vector-size
	int size=tag.size();

	//Allocate XMLCh for tags
	static XMLCh **pOutputEncoding;
	pOutputEncoding= (XMLCh** ) malloc(size * sizeof(XMLCh*));

	//Translate Tags
	for(int i=0; i<size; i++){
			pOutputEncoding[i] = XMLString::transcode(tag[i]);
	}

	//Clear Vector
	tag.clear();
	
	//Get SQL-Statement and save in vector
	for(i=0; i<size; i++){
		sql_statements = 
get_xml_document()->getElementsByTagName(pOutputEncoding[i]);
		tag.push_back(XMLString::transcode(sql_statements->item(0)->getTextContent()));
		XMLString::release(&pOutputEncoding[i]);
	}

	//Release Memory
	free(pOutputEncoding);
} 


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory-Release after using DOMNodeList*?

Posted by Alberto Massari <am...@progress.com>.
At 09.42 05/03/2004 +0100, Patrick Wicki wrote:
>Hello,
>Can anybody tell me, how to release a DOMNodeList*? Or do you happen to 
>see what causes a memory leak in the function below!
>
>[...]
>         //Get SQL-Statement and save in vector
>         for(i=0; i<size; i++){
>                 sql_statements = 
> get_xml_document()->getElementsByTagName(pOutputEncoding[i]);
> 
>tag.push_back(XMLString::transcode(sql_statements->item(0)->getTextContent()));

You are pushing a CString into the vector, but you are initializing it 
using the "transcode" method: you need to release that temp buffer.

                 char* 
pStr=XMLString::transcode(sql_statements->item(0)->getTextContent());
                 tag.push_back(pStr);
                 XMLString::release(&pStr);

Alberto

>                 XMLString::release(&pOutputEncoding[i]);
>         }
>
>         //Release Memory
>         free(pOutputEncoding);
>}
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org