[Plib-devel] Memory leak in AC loader
Brought to you by:
sjbaker
From: Durk T. <d.t...@xs...> - 2006-09-30 06:50:58
|
Dear plib developers, Recently, I've been trying to hunt down memory leaks in FlightGear, and ran it through valgrind. One of the results coming out of valgrind is that there appears to be a memory leak in plib's AC3d Model loader. In ssgLoadAC.cxx, there is a static variable mlist, which is a static array of pointers to _ssgMaterial objects: on line 295 of this file, a new ssgMaterial object is created for each material: mlist [ num_materials ] = new _ssgMaterial ; It looks like these objects are never deleted, so my proposed solution is to delete these objects at the end of the ssgEntity *ssgLoadAC ( const char *fname, const ssgLoaderOptions* options ) function, like this. for (int i = 0; i < num_materials; i++) { delete mlist[i]; } I have tested this solution for about two weeks in my local copy of plib, using FlightGear. My copy of FlightGear handles a high load of AI driven aircraft, which includes, in turn, a high load of ac3d model loading and unloading and the code appears to run without any sign of trouble. I haven't prepared an official patch yet, as I'm not sure what the current procedure for submitting plib patches is. I'd be perfectly happy to commit the patch myself (I am registered under the developer name durktalsma on sourceforge). Cheers, Durk |