discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Crash in NSKeyValueObserving.m


From: Mathias Bauer
Subject: Crash in NSKeyValueObserving.m
Date: Thu, 16 Jan 2014 15:49:22 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Hi,

I got a crash when using NSOperations. The root cause of the crash seems to be that the implementation of "didChangeValueForKey" in NSKeyValueObserving.m has a problem when an observer does unregister in the notification. In this case the variable "pathInfo" in the following code gets destroyed (you can also see how the crash can be avoided by adding a retain/release on pathInfo in the right places):

- (void) didChangeValueForKey: (NSString*)aKey
{
  GSKVOPathInfo *pathInfo;
  GSKVOInfo     *info;

  info = (GSKVOInfo *)[self observationInfo];
  if (info == nil)
    {
      return;
    }

  pathInfo = [info lockReturningPathInfoForKey: aKey];
  if (pathInfo != nil)
    {
        [pathInfo retain];                      //!!fixes the crash
      if (pathInfo->recursion == 1)
        {
          id    value = [self valueForKey: aKey];

          if (value == nil)
            {
              value = null;
            }
          [pathInfo->change setValue: value
                              forKey: NSKeyValueChangeNewKey];
          [pathInfo->change setValue:
            [NSNumber numberWithInt: NSKeyValueChangeSetting]
            forKey: NSKeyValueChangeKindKey];
          [pathInfo notifyForKey: aKey ofInstance: [info instance] prior: NO];  
// here pathInfo may get destroyed if removeObserver is called
        }
      if (pathInfo->recursion > 0)
        {
          pathInfo->recursion--;
        }
      [info unlock];
        [pathInfo release];                     //!!fixes the crash             
    }

  [self didChangeValueForDependentsOfKey: aKey];
}

Would that be an acceptable fix or should that be fixed differently?

Best regards,
Mathias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]