Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > memory corruption while debugging

Reply
Thread Tools

memory corruption while debugging

 
 
Noa Garnett
Guest
Posts: n/a
 
      08-24-2004
I'm developing on C++, using visual studio 6.0 with service pack 5.
I have a memory corruption while debugging. Some of the variables I'm
using are suddenly set to zero while progressing along the code.
The specific location of the memory corruption depends on the names I
give my local variables, on putting some of the codes in curly
brackets - {}, and on having the watch window open.
I already cleaned and re-built my project.
Can anyone help??

thanks
Noa Garnett
 
Reply With Quote
 
 
 
 
Niels Dybdahl
Guest
Posts: n/a
 
      08-24-2004
> I'm developing on C++, using visual studio 6.0 with service pack 5.
> I have a memory corruption while debugging. Some of the variables I'm
> using are suddenly set to zero while progressing along the code.
> The specific location of the memory corruption depends on the names I
> give my local variables, on putting some of the codes in curly
> brackets - {}, and on having the watch window open.
> I already cleaned and re-built my project.
> Can anyone help??


Two suggestions:
1. Single step through your application
2. Use something like boundschecker

Niels Dybdahl


 
Reply With Quote
 
 
 
 
Peter Koch Larsen
Guest
Posts: n/a
 
      08-24-2004

"Niels Dybdahl" <(E-Mail Removed)-graphics.com> skrev i en meddelelse
news:412ae6ab$0$159$(E-Mail Removed). ..
> > I'm developing on C++, using visual studio 6.0 with service pack 5.
> > I have a memory corruption while debugging. Some of the variables I'm
> > using are suddenly set to zero while progressing along the code.
> > The specific location of the memory corruption depends on the names I
> > give my local variables, on putting some of the codes in curly
> > brackets - {}, and on having the watch window open.
> > I already cleaned and re-built my project.
> > Can anyone help??

>
> Two suggestions:
> 1. Single step through your application
> 2. Use something like boundschecker
>
> Niels Dybdahl
>
>


3. Ask in a Microsoft newsgroup
4. Set a data breakpoint on the variable

/Peter


 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      08-24-2004

"Noa Garnett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I'm developing on C++, using visual studio 6.0 with service pack 5.
> I have a memory corruption while debugging. Some of the variables I'm
> using are suddenly set to zero while progressing along the code.
> The specific location of the memory corruption depends on the names I
> give my local variables, on putting some of the codes in curly
> brackets - {}, and on having the watch window open.
> I already cleaned and re-built my project.
> Can anyone help??
>
> thanks
> Noa Garnett


It may not actually be memory corruption (although, not seeing the code, it
certainly *could* be). It may be that your debugger is simply confused.

In VC++6, I've seen the debugger get confused as to which variable it's
actually looking at when there are multiple variables with the same name.
But, I've also had actual behavior problems (not just debugger issues) when
using VC++6 and having multiple instaces of variables with the same name.

Check for any local variables that are declared twice, or that have the same
name as a member (or global) variable. If you're using the same named
variable twice, try declaring it just once at the top of the function, or
else renaming each instance (such as i1, i2, and i3 instead of just i for
them all). This includes loop variables! If you've got a local variable
named the same as a class member or global, try renaming it to something
else.

-Howard


 
Reply With Quote
 
Noa Garnett
Guest
Posts: n/a
 
      08-25-2004
"Howard" <(E-Mail Removed)> wrote in message news:<SmJWc.242643$(E-Mail Removed)>...
> "Noa Garnett" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > I'm developing on C++, using visual studio 6.0 with service pack 5.
> > I have a memory corruption while debugging. Some of the variables I'm
> > using are suddenly set to zero while progressing along the code.
> > The specific location of the memory corruption depends on the names I
> > give my local variables, on putting some of the codes in curly
> > brackets - {}, and on having the watch window open.
> > I already cleaned and re-built my project.
> > Can anyone help??
> >
> > thanks
> > Noa Garnett

>
> It may not actually be memory corruption (although, not seeing the code, it
> certainly *could* be). It may be that your debugger is simply confused.
>
> In VC++6, I've seen the debugger get confused as to which variable it's
> actually looking at when there are multiple variables with the same name.
> But, I've also had actual behavior problems (not just debugger issues) when
> using VC++6 and having multiple instaces of variables with the same name.
>
> Check for any local variables that are declared twice, or that have the same
> name as a member (or global) variable. If you're using the same named
> variable twice, try declaring it just once at the top of the function, or
> else renaming each instance (such as i1, i2, and i3 instead of just i for
> them all). This includes loop variables! If you've got a local variable
> named the same as a class member or global, try renaming it to something
> else.
>
> -Howard


1. thanks.
2. but the application indeed crashes later, in a way consistent with
the memory corruption I see in the debug watch.
3. I have many multiple variables with the same name. Does the
phenomenon you describe occur only while watching variables on
debugger, or can it cause problems while working on release mode, too?
 
Reply With Quote
 
Dave Townsend
Guest
Posts: n/a
 
      08-25-2004

"Noa Garnett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I'm developing on C++, using visual studio 6.0 with service pack 5.
> I have a memory corruption while debugging. Some of the variables I'm
> using are suddenly set to zero while progressing along the code.
> The specific location of the memory corruption depends on the names I
> give my local variables, on putting some of the codes in curly
> brackets - {}, and on having the watch window open.
> I already cleaned and re-built my project.
> Can anyone help??
>
> thanks
> Noa Garnett


I've been using VC++ for many years now and I've never seen this problem, I
doubt
if you are really seeing a bug in VC++. Most likely you have a memory
corruption
in your program, or you are misintepreting the behavior incorrectly. Make
sure you
do not have any expressions with side effects in your watch windows such as
x++,etc.

You could use the memory watch window and monitor the raw memory used in
your program, first get the addresses of the variables concerned and then
view the
page of memory which contains them.

Alternatively, if you might have a true heap corruption, you can call the
MFC routine
AfxCheckMemory() which will check the heap. Put these calls in the location
where the
alleged corruption is happening to narrow the hunt down.

Post some code if you can so we can peruse this problem.

dave


dave


 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      08-25-2004

"Noa Garnett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> "Howard" <(E-Mail Removed)> wrote in message

news:<SmJWc.242643$(E-Mail Removed)>...
> > "Noa Garnett" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) om...
> > > I'm developing on C++, using visual studio 6.0 with service pack 5.
> > > I have a memory corruption while debugging. Some of the variables I'm
> > > using are suddenly set to zero while progressing along the code.
> > > The specific location of the memory corruption depends on the names I
> > > give my local variables, on putting some of the codes in curly
> > > brackets - {}, and on having the watch window open.
> > > I already cleaned and re-built my project.
> > > Can anyone help??
> > >
> > > thanks
> > > Noa Garnett

> >
> > It may not actually be memory corruption (although, not seeing the code,

it
> > certainly *could* be). It may be that your debugger is simply confused.
> >
> > In VC++6, I've seen the debugger get confused as to which variable it's
> > actually looking at when there are multiple variables with the same

name.
> > But, I've also had actual behavior problems (not just debugger issues)

when
> > using VC++6 and having multiple instaces of variables with the same

name.
> >
> > Check for any local variables that are declared twice, or that have the

same
> > name as a member (or global) variable. If you're using the same named
> > variable twice, try declaring it just once at the top of the function,

or
> > else renaming each instance (such as i1, i2, and i3 instead of just i

for
> > them all). This includes loop variables! If you've got a local

variable
> > named the same as a class member or global, try renaming it to something
> > else.
> >
> > -Howard

>
> 1. thanks.
> 2. but the application indeed crashes later, in a way consistent with
> the memory corruption I see in the debug watch.
> 3. I have many multiple variables with the same name. Does the
> phenomenon you describe occur only while watching variables on
> debugger, or can it cause problems while working on release mode, too?


It happens in my release builds, too, (but only with my apps built with
VC++, as far as I can tell). When I changed my local variables' names to be
unique (with respect to each other, and to global variables, and to member
variables), the problems went away. (It's fine to have local variables in
one function the same as local variables in another function, though, since
they're in different scopes.)

-Howard




 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      08-25-2004

"Noa Garnett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> "Howard" <(E-Mail Removed)> wrote in message

news:<SmJWc.242643$(E-Mail Removed)>...
> > "Noa Garnett" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) om...
> > > I'm developing on C++, using visual studio 6.0 with service pack 5.
> > > I have a memory corruption while debugging. Some of the variables I'm
> > > using are suddenly set to zero while progressing along the code.
> > > The specific location of the memory corruption depends on the names I
> > > give my local variables, on putting some of the codes in curly
> > > brackets - {}, and on having the watch window open.
> > > I already cleaned and re-built my project.
> > > Can anyone help??
> > >
> > > thanks
> > > Noa Garnett

> >
> > It may not actually be memory corruption (although, not seeing the code,

it
> > certainly *could* be). It may be that your debugger is simply confused.
> >
> > In VC++6, I've seen the debugger get confused as to which variable it's
> > actually looking at when there are multiple variables with the same

name.
> > But, I've also had actual behavior problems (not just debugger issues)

when
> > using VC++6 and having multiple instaces of variables with the same

name.
> >
> > Check for any local variables that are declared twice, or that have the

same
> > name as a member (or global) variable. If you're using the same named
> > variable twice, try declaring it just once at the top of the function,

or
> > else renaming each instance (such as i1, i2, and i3 instead of just i

for
> > them all). This includes loop variables! If you've got a local

variable
> > named the same as a class member or global, try renaming it to something
> > else.
> >
> > -Howard

>
> 1. thanks.
> 2. but the application indeed crashes later, in a way consistent with
> the memory corruption I see in the debug watch.
> 3. I have many multiple variables with the same name. Does the
> phenomenon you describe occur only while watching variables on
> debugger, or can it cause problems while working on release mode, too?


Other thoughts: if your'e seeing memory corruption, look especially for
code that writes beyond the end of an array, or use of pointers that have
not been properly initialized before their first use, or where the objects
they point to have been deleted. Such errors can cause problems in
completely separate parts of your code, and are most often the culprits for
*strange* behavior.

-Howard



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid memory corruption in shared memory used by several processes? Sune C Programming 14 08-26-2007 03:57 AM
Avoid memory corruption in shared memory used by several processes? Sune C Programming 5 07-13-2007 02:29 PM
Microsoft Internet Explorer COM Object Instantiation Memory Corruption Vulnerability Imhotep Computer Security 2 12-15-2005 03:03 PM
iDEFENSE Security Advisory 02.28.05: Mozilla Firefox and,MozillaBrowser Out Of Memory Heap Corruption Design Error winged Computer Security 1 03-02-2005 01:56 AM
Got error msg while Debugging : Error while trying to run project: ... ^CrazyCoder^ ASP .Net 3 09-15-2003 09:40 AM



Advertisments