goat3d

changeset 45:8da36540e2e9

fixed memory leak in readxml and reversed error return
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 08 Dec 2013 02:27:32 +0200
parents f8bfc3177582
children 9d911100935b
files src/goat3d.cc src/goat3d_readxml.cc
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/goat3d.cc	Sun Dec 08 02:14:46 2013 +0200
     1.2 +++ b/src/goat3d.cc	Sun Dec 08 02:27:32 2013 +0200
     1.3 @@ -132,7 +132,7 @@
     1.4  GOAT3DAPI int goat3d_load_io(struct goat3d *g, struct goat3d_io *io)
     1.5  {
     1.6  	if(!g->scn->load(io)) {
     1.7 -		if(g->scn->loadxml(io)) {
     1.8 +		if(!g->scn->loadxml(io)) {
     1.9  			return -1;
    1.10  		}
    1.11  	}
     2.1 --- a/src/goat3d_readxml.cc	Sun Dec 08 02:14:46 2013 +0200
     2.2 +++ b/src/goat3d_readxml.cc	Sun Dec 08 02:27:32 2013 +0200
     2.3 @@ -19,6 +19,7 @@
     2.4  	char *buf = new char[bytes];
     2.5  	if(io->read(buf, bytes, io->cls) < bytes) {
     2.6  		logmsg(LOG_ERROR, "failed to read XML scene file\n");
     2.7 +		delete [] buf;
     2.8  		return false;
     2.9  	}
    2.10  
    2.11 @@ -27,12 +28,14 @@
    2.12  	if(err) {
    2.13  		logmsg(LOG_ERROR, "failed to parse XML scene file: %s\n%s\n", xml.GetErrorStr1(),
    2.14  				xml.GetErrorStr2());
    2.15 +		delete [] buf;
    2.16  		return false;
    2.17  	}
    2.18  
    2.19  	XMLElement *root = xml.RootElement();
    2.20  	if(strcmp(root->Name(), "scene") != 0) {
    2.21  		logmsg(LOG_ERROR, "invalid XML file, root node is not <scene>\n");
    2.22 +		delete [] buf;
    2.23  		return false;
    2.24  	}
    2.25  
    2.26 @@ -58,7 +61,8 @@
    2.27  		elem = elem->NextSiblingElement("mesh");
    2.28  	}
    2.29  
    2.30 -	return false;
    2.31 +	delete [] buf;
    2.32 +	return true;
    2.33  }
    2.34  
    2.35