Fortify for memory leakage

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Fortify for memory leakage

Post by Yustme »

Hi,

Did anyone succeeded in getting Fortify to show memory leakages with showing file and line number where it occurs using visual studio 2005?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I'm not really sure why the compiler/IDE would be relevant. We're talking about this Fortify, yes? What problems are you having with it?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

Hi,

Yes, that Fortify. The problem is, it's not showing me any memory leakage in the output window of my IDE.

The documentation of Fortify says that it might not work for your compiler/IDE, then i would have to adjust something for Fortify to recognize my compiler/IDE.

That's why the compiler/IDE is relevant i guess.

I placed this function:

Code: Select all

Fortify_EnterScope();

Just right at the start of my main function

And ended my main just in front of the return 0, with this function:

Code: Select all

Fortify_LeaveScope();

No .log file is made and nothing in my output window.

What am i doing wrong?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Heh, you're right; it is an IDE issue.

Code: Select all

static void
st_DefaultOutput(const char *String)
{
    fprintf(stdout, String);
    fflush(stdout);
}
You'll want to add an OutputDebugString() in there if you want it to come out in the debugger's output. It should appear in a console though; have you suppressed the console?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

rogerborg wrote:Heh, you're right; it is an IDE issue.

Code: Select all

static void
st_DefaultOutput(const char *String)
{
    fprintf(stdout, String);
    fflush(stdout);
}
You'll want to add an OutputDebugString() in there if you want it to come out in the debugger's output. It should appear in a console though; have you suppressed the console?

Hi,

Once i press the ESC button, my game is closed. The console gets closed too. But i have implemented:

Code: Select all

system("pause");
Too see if Fortify is showing me the memory leakages in the console.

Unfortunately, that wasn't the case.

The debug tool of microsoft does show me that memory leakage happens but not the lines where it occurs because i am not using "new" or "malloc" to allocate memory.

I am not sure what to do with the functions you provided. They expect a string as an argument.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

It's another method to do it but maybe you'll find it useful:
http://forums.microsoft.com/MSDN/ShowPo ... 4&SiteID=1
http://www.codeguru.com/forum/archive/i ... 12742.html
http://osdir.com/ml/lib.wxwindows.gener ... ml?rfp=dta

I haven't read them yet but they're open in the tabs since I found them (few days ago) waiting to be learned..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Visual Leak Detector

http://dmoulding.googlepages.com/vld

Easier and better, IMO, then Purify or any other solutions.

You simply #include <vld.h> and any output that Visual Studio would normally report will have more information.
Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Yustme wrote:The debug tool of microsoft does show me that memory leakage happens but not the lines where it occurs because i am not using "new" or "malloc" to allocate memory.
I'm almost afraid to ask how you're allocating memory if it's not with new() or malloc().

OK, have you read the Fortify manual?
To install Fortify, each source file will need to #include "fortify.h".
To enable Fortify, define the symbol FORTIFY. The makefile is the best
place to do this. The symbol FORTIFY will need to be defined for every
module, this includes "fortify.c" or "fortify.cxx"

If you do not have stdout available, you may wish to set an alternative
output function. See Fortify_SetOutputFunc() and FORTIFY_AUTOMATIC_LOGFILE, below.
If so, then I suggest that you set breakpoints in the fortify functions (e.g. Fortify_malloc()) and check that they're actually being called. If not, then there's something hooky in your setup, and you need to RTFM a bit more.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Spintz wrote:Visual Leak Detector

http://dmoulding.googlepages.com/vld

Easier and better, IMO, then Purify or any other solutions.

You simply #include <vld.h> and any output that Visual Studio would normally report will have more information.
What does that mean in simple words?:

Code: Select all

// Force a symbolic reference to the global VisualLeakDetector class object from
// the DLL. This enusres that the DLL is loaded and linked with the program,
// even if no code otherwise imports any of the DLL's exports.
#pragma comment(linker, "/include:__imp_?vld@@3VVisualLeakDetector@@A")
Edit:
When I run it I get a massive list of so called memory leaks but I don't understand how to read it, it just show me many places of my code..
Something like that:

Code: Select all

WARNING: Visual Leak Detector detected memory leaks!
---------- Block 287 at 0x01C738C8: 60 bytes ----------
  Call Stack:
    d:\programming\projects\active projects\visual studio 2008\nusoftware products\svn\nusoftware game engine sdk\trunk\source\nusoftware game engine\core\cgamemanager.cpp (153): nge::CGameManager::Init
    d:\programming\projects\active projects\visual studio 2008\nusoftware products\svn\nusoftware game engine sdk\trunk\source\nusoftware game engine\core\cgamemanager.cpp (43): nge::CGameManager::CGameManager
    d:\programming\projects\active projects\visual studio 2008\nusoftware products\svn\nusoftware game engine sdk\trunk\source\nusoftware game engine\core\cgame.cpp (8): nge::CGame::CGame
    d:\programming\projects\active projects\visual studio 2008\nusoftware products\svn\nusoftware game engine sdk\trunk\examples\01.helloworld\helloworld.cpp (9): main
    f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (266): mainCRTStartup
    f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (182): mainCRTStartup
    0x7C816FD7 (File and line number not available): RegisterWaitForInputIdle
  Data:
    70 54 4F 00    94 54 4F 00    50 EF 3A 00    58 6C 3A 00     pTO..TO. P.:.Xl:.
    E8 81 3A 00    C0 60 C7 01    01 00 00 00    01 00 00 00     ..:..`.. ........
    01 00 CD CD    E4 54 4F 00    10 66 9C 02    01 00 00 00     .....TO. .f......
    64 54 4F 00    01 00 00 00    00 00 00 00                    dTO..... ........
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

Spintz wrote:Visual Leak Detector

http://dmoulding.googlepages.com/vld

Easier and better, IMO, then Purify or any other solutions.

You simply #include <vld.h> and any output that Visual Studio would normally report will have more information.
Hi,

I have tried vld a few days back. It runs my game very slow, I get 3 FPS.

When i close my game, it says "no memory leaks detected". While the MS debug tool shows at least 4 MB (after counting them all).
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

rogerborg wrote:
Yustme wrote:The debug tool of microsoft does show me that memory leakage happens but not the lines where it occurs because i am not using "new" or "malloc" to allocate memory.
I'm almost afraid to ask how you're allocating memory if it's not with new() or malloc().

OK, have you read the Fortify manual?
To install Fortify, each source file will need to #include "fortify.h".
To enable Fortify, define the symbol FORTIFY. The makefile is the best
place to do this. The symbol FORTIFY will need to be defined for every
module, this includes "fortify.c" or "fortify.cxx"

If you do not have stdout available, you may wish to set an alternative
output function. See Fortify_SetOutputFunc() and FORTIFY_AUTOMATIC_LOGFILE, below.
If so, then I suggest that you set breakpoints in the fortify functions (e.g. Fortify_malloc()) and check that they're actually being called. If not, then there's something hooky in your setup, and you need to RTFM a bit more.

Hi,

I just get a few pointers like the device and driver.

Do you use "malloc" or "new" for that?
Post Reply