Vis-Sim.com Forums Forum Index Vis-Sim.com Forums
3D Real-Time Simulation Services, Resources and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Memory Problems detecting dormant failures on win32

 
Post new topic   Reply to topic    Vis-Sim.com Forums Forum Index -> C /C++
View previous topic :: View next topic  
Author Message
boto
User


Joined: 08 Jul 2005
Posts: 6

PostPosted: Fri Jul 08, 2005 10:29 pm    Post subject: Memory Problems detecting dormant failures on win32 Reply with quote

hi guys,

currently i have also a nerving crash problem, but i think in my case the linked libs are the right one Sad

does somebody have any interest to help me?

cheers
boto
Back to top
View user's profile Send private message
UrbanLegend
Site Admin


Joined: 11 Apr 2005
Posts: 1147

PostPosted: Sun Jul 10, 2005 2:36 pm    Post subject: Reply with quote

At least several possible culprits stand out to me in this type of thing

1)Your mixing release and debug library versions, see my post http://www.3drealtimesimulation.com/3dsceneBB/viewtopic.php?p=83#83 it explains how to set up VS correctly, also Mike Wieblen rebuilt all of the 3rd party libraries with the correct linkage to help avoid these problems, see the downloads section on the OSG web site

2)Your trying to allocate too much memory, check the size your asking for, its quite common to generate a bad number of bytes to request

3)un-Initialise variables, or bad values, this can cause problems when using new for array's etc.

4 )Your returning address of a temp stack variable from a function and using the data at the dead address, this will effect 2 & 3 above

5)A Multi-process/thread problem of trying to use data/objects in different threads without protecting the data with semaphores or locks etc. Most folks really do get caught on this when using a GUI with API like OSG, Vega etc... You have to create an MP safe mechanism for this in a GUI based program

6)Your trying to allocate an use memory across thread boundaries


Last edited by UrbanLegend on Sun Jul 10, 2005 3:35 pm; edited 2 times in total
Back to top
View user's profile Send private message
boto
User


Joined: 08 Jul 2005
Posts: 6

PostPosted: Sun Jul 10, 2005 2:56 pm    Post subject: Reply with quote

hi,

UrbanLegend wrote:
At least several possible culprits stand out to me in this type of thing

1)Your mixing release and debug library versions, see my post http://www.3drealtimesimulation.com/3dsceneBB/viewtopic.php?p=83#83 it explains how to set up VS correctly, also Mike Wieblen rebuilt all of the 3rd party libraries with the correct linkage to help avoid these problems, see the downloads section on the OSG web site


i have rebuilt all libs and made sure that all libs are compiled with right flags for supporting multi-threading. when did mike rebuild the 3th party libs? i have those shipped with osg 0.9.9. i may check them again. those libs are the only one which i did not check (except freetype which i have rebuilt.)

UrbanLegend wrote:

2)Your trying to allocate too much memory, check the size your asking for, its quite common to generate a bad number of bytes to request


nop, the crash happens with valid and plausible requested mem sizes. i can observe that when the crash happens.

UrbanLegend wrote:

3)un-Initialise variables, or bad values, this can cause problems when using new for array's etc.


i have checked the code several times for such errors; very unlikely that the code contains such errors.

UrbanLegend wrote:

3)Your returning address temp heap variable from a function and using the data at the dead address, this will effect 2 & 3 above


please, explain me more on this kind of error; i don't get what you mean Sad

UrbanLegend wrote:

4)A Multi-process/thread problem of trying to use data/objects in different threads without protecting the data with semaphores or locks etc. Most folks really do get caught on this when using a GUI with API like OSG, Vega etc... You have to create an MP safe mechanism for this in a GUI based program


i can exclude also such errors with high likelihood.

UrbanLegend wrote:

5)Your trying to allocate an use memory across thread boundaries


how can this case (5) happen? could you please explain me this case with a simple example?


thanx a lot UrbanLegend.

cheers
boto
Back to top
View user's profile Send private message
UrbanLegend
Site Admin


Joined: 11 Apr 2005
Posts: 1147

PostPosted: Sun Jul 10, 2005 3:34 pm    Post subject: Reply with quote

Opps
should be

4 )Your returning address of a temp stack variable from a function and using the data at the dead address, this will effect 2 & 3 above


Heap should have been stack
Back to top
View user's profile Send private message
boto
User


Joined: 08 Jul 2005
Posts: 6

PostPosted: Sun Jul 10, 2005 5:07 pm    Post subject: Reply with quote

4) can be excluded too Sad there is no such construct in code.

cheers
boto
Back to top
View user's profile Send private message
boto
User


Joined: 08 Jul 2005
Posts: 6

PostPosted: Mon Jul 11, 2005 1:48 pm    Post subject: Reply with quote

hi,

eventually i could find the source of .., it was something like following code:

Code:


// copy an ascii file into an internal std::string buffer

std::fstream file;
std::size_t   filesize = 0;
std::string    buffer;
char*         p_buf = NULL;

 // open a file and determine its size, then read it into p_buf
...

//now the interesting part:

buffer = p_buf;   // until here everything is legal and ok

// now append a special end of string postfix into the string buffer (char sequence 13, 0)

// here is the .. code
buffer[ filesize ] = static_cast< char >( 13 );
buffer[ filesize + 1 ] = '\0';

// the correct code looks so
buffer += static_cast< char >( 13 );
buffer += '\0';



i had exceeded the std string's char buffer boundary by two bytes in the last two lines of code above.

this failure was very subtile and caused the occasional crash. what i wonder is why a dynamic mem checker was not able to discover this error!? i guess because the two bytes were inside the string object but not inside of the string buffer of the object!? i had expected that a mem checker is exactly for discovery this sort of errors, brrrr Sad

# some words to the way how i came to the error location:

i have used a small function which does windows heap validation, it looks as follows:

Code:

#ifdef WIN32

#define MAX_HEAPS_VALIDATE  20
void heapCheck()
{
    HANDLE heaps[ MAX_HEAPS_VALIDATE ]; // we can check up to 20 heaps
    DWORD numHeaps = GetProcessHeaps( MAX_HEAPS_VALIDATE, heaps );
    for ( DWORD curHeap = 0; curHeap < numHeaps; curHeap++ )
    {
        if ( HeapValidate( heaps[ curHeap ], 0, NULL ) == FALSE )
        {
              __asm int 3; // trigger a user break point
        }
    }
}

#endif



as the crash happened often when the application started NOT in a vc debug session (it has to do with vc debugger's initialization of heap segments on start up), i placed an additional "__asm int 3;" into beging of the app (e.g. in main function) in order to be able to start the app without the debugger and to trigger the vc debugger after starting the app (a message box pops up and then you can start the debugger by clicking on "Cancel" button, then let the app continue running).

some additional notes: i have built the app and the libs in release, but let the compiler and linker generate debug info in order to get the source code during debugging, not only the assembly. i have placed the heapCheck() funtion call at various places in app code where the initialization of different libs happens and in addition i placed it into main loop -- things get slowed down if the heap validation is done in every loop step, but it was worth it Wink

after a while a heap corruption occured because of the code shown above and my "int 3" in checkHeap() triggered a break in debugger and the output console of vc ide showed me a message which came from HeapAlloc complaining about heap corruption at a particular address while the application was requesting for memory using new or malloc. evaluating the content of that memory address brought me to the location of .. code above; i could recognize some config file contentes which i read in using the code above.

one last note: you can also ommit the "int 3" in main entry, however this way you will get the user break point in heapCheck() triggered when a heap corruption has been detected, so when at this time your debugger is not hooked into your app so you will miss the important output message from HeapAlloc complaining about the corruption location.

cheers
boto


Last edited by boto on Mon Jul 11, 2005 3:02 pm; edited 2 times in total
Back to top
View user's profile Send private message
UrbanLegend
Site Admin


Joined: 11 Apr 2005
Posts: 1147

PostPosted: Mon Jul 11, 2005 2:52 pm    Post subject: Reply with quote

Good to hear you found the issue and thanks for sharing problem and answer
Back to top
View user's profile Send private message
boto
User


Joined: 08 Jul 2005
Posts: 6

PostPosted: Mon Jul 11, 2005 3:00 pm    Post subject: Reply with quote

thank you very much UrbanLegend, your advices really helped me Wink

cheers
boto
Back to top
View user's profile Send private message
UrbanLegend
Site Admin


Joined: 11 Apr 2005
Posts: 1147

PostPosted: Mon Jul 11, 2005 3:24 pm    Post subject: Reply with quote

I know how frustrating it gets trying to track down those types of issues

My desk has blood splaters and dents from me banging my head against it so much Smile
Back to top
View user's profile Send private message
boto
User


Joined: 08 Jul 2005
Posts: 6

PostPosted: Mon Jul 11, 2005 3:39 pm    Post subject: Reply with quote

hehe, when i am getting to that emotional state then i take a long breath and think about that horror time when i was married Very Happy, suddently i get cool and quite and thank mr. god that i am now no longer married, lol Smile

cheers
boto

p.s.: i am just kidding Wink
Back to top
View user's profile Send private message
enambanis
Guest





PostPosted: Wed Apr 23, 2008 4:15 am    Post subject: The download free financial analysis software beach gallery Reply with quote

Adult Stream Video


A richard realm anal business data analyst ebony teaser . carolina holly in north sex springs sex and the city episode summaries muscle anal charge harassment sexual red head lesbians .. off . ip video to analog video pomegranate seed wharton analysis hentai sex photo lesbianism sex shop free brunette sex video .



At lisa raye sexy picture sussex county delaware government sexo en guayaquil sexy blondie comic . catalog clothes sexy bikini russian sexy california sex offender megans law sexy halter tops . lesbian tounges and toy guardian oxygen analyzer scuba air / nitrox . naked pre sex teen stiffness analysis minute long sex .



A sophia loren and sex free online read sex story cat ebony fight erotic sapphic sex video japaneses public sex . fanal fantasy tactics ebony sexy teen sussex hose pipe ebony sierra mpeg bar philippine sex gratis meando sexo orgie sexy sex porn xxx picture . norwegian sex how to locate sex offender daily hardcore sex xxx . dirty quiz sex sex and the city ringtones live sexy film . guide.tv sex travel sex can i get pregnant dymes ebony rating site hot lesbian porn videos .

anal ass asstraffic beautifulfalse sexual harassment charges - davis sextant wingman analog drivers sexy woman clothes free sex noise .
www sexy babes comkristen lesbian love story - black lesbian hoes harassment policy sexual workplace sex artwork .
sexicsde la ostia sexo - the guest analysis intercourse perform sexual ebonyjugs cart costume online sexy view sex napster dildo anal lesbo free brazil sex video sex email joke .
free heel in leg photo sexy stockinganalyzer gas miniature - old man sex picture lesbian movie spanking lesbian picture sex teen lucia sex trailer black having picture sex woman bell catherine sex tape sex friends 3 .

A .. black men having hardcore sex vh1 top sexiest songs hot lesbian girls with hot legs and feet sex change orgasm move sexy woman woman . adult emoticon sexy free kinky sex idea analyzing sources retail investment analyst sex wild things model portfolio sexy teen . busty in lingerie sexy gallery mature sex swinger woman . computer systems analysis analytical abstracts sexy black and white photos sexy brazilian jeans ebony teen pantie . megan sexy help desk analyst ookala hawaii free raw sex video recreational sex . free animal sex pics sexy dominican republic woman nickelodeon sex .



college girl sex adventure hidden camgratuiti sexy tatuaggi - anal voyeur black ebony girl picture escort evi sexy tipp .
experience fan fiction sexualanal .. porn - arican film sex financial analyst career earnings sexual indiscretion sexy clothes for black women .
adult escort idaho nampa sexarizona lawyer offender sexual - lesbian lingerie retro wearing free lesbian erotica video free live sex feed from amsterdam built canal erie who adult.com interracial pic sex sexy dominican girls horse anal .
hot lesbian latinas girldenise paglia sexy - info mexicanas remember sexo philipino sex analysis of how do i love thee analysis of group 2 cations christ sex supremacy woman sexual intercourse eeoc harassment sexual cameron diaz picture sex .
cam sexy teen websex picx - index jpg pic sex barbie having ken sex video hose in leg pantie sexy sexual pegging sexual harassment in workplace free transexual porn movie wholesale sexy clothing .

At amazing clip sex homemade sex wife abi 3100 genetic analyzer . group homes in california sexual addiction amateur having sex wife . dislike oral sex woman mov sex . strip tease sex how to perform anal intercourse direct analysis . knowing sex .. nude sex free lesbian post video contact free live online sex ass -- fireman .. naked nude sexy straight marge piercy analysis .

A escorte poze sexy analyze engine links ranking search software.2fear.com black anal fist action hump kiss naughty sexy . what woman love in sex linsey lohan sexy pic samantha anal . sexually provocative analysis write up calendarios chicas de sexy . outrageous sex acts canal street new york city grown and sexy by chamillionaire ranzige sexverhalen . support same sex marriage dargonball z sex system analysist home grown sex alleged busted high ring school sex girl girl hunting lesbian movie pressure vessel analysis . prazer anal horse on woman sex analysis of a valediction ir analyzer change procedure sex pink sex wold .
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Vis-Sim.com Forums Forum Index -> C /C++ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


SwiftBlue Theme created by BitByBit
Powered by phpBB © 2001, 2002 phpBB Group