Leaks detected by static analysis tool cppcheck, some I suspect are false postives. Patches to fix real errors are below
[./src/GriColor.hh:32]: (error) Class GriColor which is inherited by class GriNamedColor does not have a virtual destructor
[./src/GriPath.cc:521]: (all) Memory leak: r
[./src/convert.cc:406]: (error) Resource leak: tmp
[./src/gr_coll.hh:79]: (error) Class GriDvector which is inherited by class GriColumn does not have a virtual destructor
[./src/gr_coll.cc:653]: (error) Mismatching allocation and deallocation: RpnItem::name
[./src/gr_coll.cc:662]: (error) Mismatching allocation and deallocation: RpnItem::name
[./src/read.cc:125]: (error) Resource leak: fp
[./src/rpncalc.cc:1338]: (all) Memory leak: thisline
[./src/startup.cc:1015]: (error) Resource leak: _grSVG
[./src/startup.cc:827]: (error) Resource leak: _grSVG
--- convert.cc 2009-07-16 07:23:59.000000000 +1000
+++ ./convert.cc.new 2009-08-22 16:43:41.000000000 +1000
@@ -403,6 +403,7 @@
_colX[i], _colY[i], _colZ[i], gr_currentmissingvalue());
}
}
+ fclose(tmp);
}
return found;
}
--- rpncalc.cc 2009-07-16 07:23:59.000000000 +1000
+++ ./rpncalc.cc.new 2009-08-22 16:45:04.000000000 +1000
@@ -1335,6 +1335,8 @@
pipefile = (FILE *) popen(output_lines, "r");
if (!pipefile) {
err("Sorry, cannot do `system' in RPN; failed popen() call");
+ delete[] thisline;
+ delete[] output_lines;
return false;
}
strcpy(output_lines, "");
--- startup.cc 2009-07-16 07:23:59.000000000 +1000
+++ ./startup.cc.new 2009-08-22 16:45:56.000000000 +1000
@@ -825,6 +825,7 @@
_page_size.scale(CM_PER_IN);
fprintf(_grSVG, "<svg width=\"%d\" height=\"%d\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n", int(8.5*PT_PER_IN), int(11.0*PT_PER_IN));
} else {
+ fclose(_grSVG);
warning("Sorry, cannot determine type of output file; using default postscript filename instead");
}
} else {
@@ -1013,6 +1014,7 @@
_page_size.scale(CM_PER_IN);
fprintf(_grSVG, "<svg width=\"%d\" height=\"%d\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n", int(8.5*PT_PER_IN), int(11.0*PT_PER_IN));
} else {
+ fclose(_grSVG);
warning("Sorry, cannot determine type of output file; using default postscript filename instead");
}
} else {
Thanks for the report, and for the very helpful patches. I'll look into this, once I get cppcheck on my system.
The latest CVS version of Gri has been modified to address this issue,
but I would appreciate it if you could check. To do this, follow these four
steps ...
cvs -d:pserver:anonymous@gri.cvs.sourceforge.net:/cvsroot/gri login
cvs -z3 -d:pserver:anonymous@gri.cvs.sourceforge.net:/cvsroot/gri co gri
./configure
make
... and then try running this new gri on your bug file, e.g. by typing
./gri -directory . bugfile.gri
... and post here the results.
Please note: the CVS version is NOT FOR EVERYDAY use. It is just for
testing. It works on your issue AT THE MOMENT when I'm making this
report, but it could fail later, as I (or other developers) change other
things in Gri.
Thanks. Dan.
Thanks. I've made changes as suggested, except for startup.cc, where I think the _gr* files do not need to be closed in those parts of the if statement.
I did not really understand the error message about virtual destructors relating to GriColor, etc., and I am hoping that things are actually OK there. (The code has not produced problems that have been reported, and it's getting pretty old by now so it has compiled cleanly on a lot of versions of g++. I think this might mean it's ok, despite the report from cppcheck.)
PS. I downladed cppcheck, and it's a nice tool. I couldn't download the most recent version since it is a .exe file and I don't have that kind of machine, but the older version compiled fine and seemed to work. Thanks for informing me about this tool.