====> The source code link is on the bottom <====
Hi,
After one week of analyses I localize and correct some memory issues...
I don't like command line tool so i made a complete VC2008 project without Perl, script, asm and code generator (proj not include for the moment...), to allow VC full integration, I made some modification isolate with a pragma: _WZ_VC__.
Don’t be afraid, I check that project can be compiled using mingw (vc_compile.bat)
Conf: UNICODE, BUILD_WIN32, LSB_FIRST (under Win7 32bits)
List of modifications:
* Driver impacted
+ "Aliens (World set 2)"
+ "Devil World"
+ "Caveman Ninja (World ver 4)"
+ "Rohga Armor Force (Asia/Europe v5.0)"
+ "Haunted Castle (ver. M)"
+ "Gauntlet (rev 14)"
+ "Asuka & Asuka (World)"
* Hardware impacted
+ Midas
+ SNES
+ Z80
+ Taito
+ Yamaha FM sound generator
+ Irem GA20 PCM Sound Chip
+ Philips SAA1099 Sound driver
+ SN76496
+ UPD7759
* System impacted
+ samples.cpp
+ mdi.cpp
+ scrn.cpp
+ sel.cpp
+ epx.cpp
+ xbr.cpp
+ net.cpp
* Code change.
- Remove dead code.
+ Simplification
- Remove memory overrun.
+ Adjust #define
- Remove resource leak.
- Initialize uninitialized.
- Remove unused var.
Most common issue:
char a[2] = { 0, 0 }
memset (a, 0xff, 3); <- hoops we have a problem the size of the array is 2 nor 3
a[3] = value; <- hoops we have a problem a max is [2] nor a[3]…
char a [MAXPATH];
char b [MAXPATH];
strcpy ( b, a );
strcat (b, “somethings” ) <- hoops we have a problem MAXPATH + sizeof (“somethings”) is greater than MAXPATH… It's this kind of bug that creates crash on rom search mechanism if you have a big hd tree…
Correction for security I don’t adjust new string size to exact correct size, if the corrected size is 18, I put 24, if its 28, I put 32, if it’s 192, I put 256…
I don’t correct yet all memory issue because some one required more analyze to be sure that it’s really a problem…
For resource leak it’s a little more tricky :
According to MSDN, brush created with CreateSolidBrush(0); must be destroy using DeleteObject, so instead of add a mechanism to release resource, I replace the brush creation by a function that return system brush that do not need to be release GetStockObject.
A found a strange memory leak when I play with Metal Slug X it’s so big that it strange:
SZHVC_add and SZHVC_sub (2x256x256) don’t seems to be release, so I add some code to do the job on Z80Exit...
A big part of the code what disable using #if 0, on this code, memory was release, it’s why I found this strange…
If you use my mod don’t forget to add my pseudo on credit ^_^ : “Wizard Coder”…
Are you interest by the vc2008 project, for debugging and for using visual plug-in like “static code analyze” or “memory leak detector” it’s useful…
WCoder
Note 1 : For more details on mod, use diff tool…
Note 2 : After a coding night the gatcha image is not easy to read...
Note 3 : Archive to big :
http://www.mediafire.com/file/0tobysc4o2qe2zs/svn.1074.rar – pwd : fba