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
_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep