bug in XmlDocument.cpp (viz-plugins)
#1
from cxmldocument::load(char*)

Quote: m_doc = (char*) malloc(m_size); //***********
if (!m_doc)
{
m_size = 0;
fclose(hfile);
return -2;
}

if (fread(m_doc, m_size, 1, hfile)<=0)
{
delete m_doc; //************
m_doc = 0;
m_size = 0;
fclose(hfile);
return -3;
}

malloc and delete mixed. baaad. and the buffer is not deleted in the destructor => memleak...
Reply
#2
Thumbs Down 
i thought about that a bit and found the answer by myself:
there's a malloc, because "new" would've needed another import-function (??2@yapaxi@z from msvcr71) and that's not included in the msvcr71-emulation-layer!

and mixing malloc and delete seems to break the whole structure (when you include the import-functions into the emu-layer).

oh, and not including the functions into the emulayer the delete in the function does nothing, because it's an unemulated import => dummy-import => do nothing and everything is ok...
Reply
#3
corrected cxmldocument (parts of it):

Quote:void cxmldocument::create(char* szstring)
{
m_size = strlen(szstring);
m_doc = new char[m_size+1];
memcpy(m_doc, szstring, m_size+1);
}

cxmldocument::~cxmldocument()
{
if(m_doc) {
delete[] m_doc;
m_doc = null;
}
}



//////////////////////////////////////////////////////////////////////////////////
// function: xml_load_doc
// opens an xml document and loads it into memory.
//
int cxmldocument::load(char* szfile)
{
file* hfile;

hfile = fopen(szfile,"rb");
if (hfile==null)
{
return -1;
}

fseek(hfile,0,seek_end);
m_size = ftell(hfile);

fseek(hfile,0,seek_set);

m_doc = new char[m_size];
if (!m_doc)
{
m_size = 0;
fclose(hfile);
return -2;
}

if (fread(m_doc, m_size, 1, hfile)<=0)
{
delete[] m_doc;
m_doc = 0;
m_size = 0;
fclose(hfile);
return -3;
}

fclose(hfile);
return 0;
}








//////////////////////////////////////////////////////////////////////////////////
// function: xml_close_doc
// closes xml document freeing up resources.
//
void cxmldocument::close()
{
if (m_doc!=null)
{
delete[] m_doc;
m_doc =0;
}

m_size =0;
m_nodes = 0;
m_sztag[0] = 0;
m_sztext[0] = 0;
}



and every viz-plugin using it needs a recompile...
Reply

Logout Mark Read Team Forum Stats Members Help
bug in XmlDocument.cpp (viz-plugins)0