[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: Strange crashes

From: Lübbe Onken <l.onken_at_rac.de>
Date: 2006-04-10 09:40:39 CEST

Hi Steve,

You wrote:

> if (cachedDir)
> return m_mostRecentStatus = cachedDir->GetStatusForMember(...);
>
> The crash happens on the second line, because 'cachedDir' is NULL!
> Now, how can it crash there? The if() statement above should
> make sure
> that 'cachedDir' isn't NULL when the second line is executed.

This can happen if cachedDir points to an object, that has been destroyed
somewhere else. It can become a real bitch to track down, because depending
on your 'luck' the place that cachedDir points to can still be a valid
object of the proper type for some time until the memory really gets
overwritten.

Do you (for example) have a cachedDirList somewhere? Assume cachedDir points
to a member of the list. The list gets freed at some other place and
cachedDir never gets to know that this has happened.

A good way to get around this is to implement the observer pattern. Short
version: Each object being watched has a list of its observers. In its
destructor it notifies the observers of its destruction. It can also notify
the observers of other changes if need be. Each observer adds/removes itself
to/from the objects list of observers when he starts/stops watching an
object.

I am working on a measurement application, where lots of windows have to
monitor changes in a lot of objects, which can show up, change and
dissappear at any time (from the windows point of view) and the observer
pattern really helps a lot.

Cheers
- Lübbe

--
       ___
  oo  // \\      "De Chelonian Mobile"
 (_,\/ \_/ \     TortoiseSVN
   \ \_/_\_/>    The coolest Interface to (Sub)Version Control
   /_/   \_\     http://tortoisesvn.tigris.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Mon Apr 10 09:41:00 2006

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.