diff --git a/ChangeLog b/ChangeLog index e4945d44c..486ca86cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-02-07 Richard Frith-Macdonald + + * Source/NSKeyedUnarchiver.m: Changes to fix memory leaks. + Fix bug handling nil/NSnull reported by Fred. + 2004-02-06 Richard Frith-Macdonald * Source/GSHTTPURLHandle.m: If there is no path in the URL, assume '/' diff --git a/Source/NSKeyedUnarchiver.m b/Source/NSKeyedUnarchiver.m index 498c110ca..85005c990 100644 --- a/Source/NSKeyedUnarchiver.m +++ b/Source/NSKeyedUnarchiver.m @@ -34,9 +34,9 @@ /* * Setup for inline operation of arrays. */ -#define GSI_ARRAY_RETAIN(A, X) -#define GSI_ARRAY_RELEASE(A, X) -#define GSI_ARRAY_TYPES GSUNION_OBJ|GSUNION_SEL|GSUNION_PTR +#define GSI_ARRAY_RETAIN(A, X) RETAIN((X).obj) +#define GSI_ARRAY_RELEASE(A, X) RELEASE((X).obj) +#define GSI_ARRAY_TYPES GSUNION_OBJ #include @@ -191,7 +191,6 @@ static NSMapTable globalClassMap = 0; } } - savedCursor = _cursor; savedKeyMap = _keyMap; @@ -199,7 +198,7 @@ static NSMapTable globalClassMap = 0; _keyMap = obj; // Dictionary describing object o = [c allocWithZone: _zone]; // Create instance. - // Store object in map so that decoding of it cn be self refrential. + // Store object in map so that decoding of it can be self referential. GSIArraySetItemAtIndex(_objMap, (GSIArrayItem)o, index); r = [o initWithCoder: self]; if (r != o) @@ -232,25 +231,24 @@ static NSMapTable globalClassMap = 0; GSIArraySetItemAtIndex(_objMap, (GSIArrayItem)o, index); } } - - if (o == nil) - { - obj = RETAIN(GSIArrayItemAtIndex(_objMap, 0).obj); - } - else - { - obj = o; - } - + RELEASE(o); // Retained in array + obj = o; _keyMap = savedKeyMap; _cursor = savedCursor; } else { - RETAIN(obj); // Use the decoded object directly + // Use the decoded object directly GSIArraySetItemAtIndex(_objMap, (GSIArrayItem)obj, index); } + if (obj == nil) + { + // Record NSNull marker for decoded object. + o = GSIArrayItemAtIndex(_objMap, 0).obj; + GSIArraySetItemAtIndex(_objMap, (GSIArrayItem)o, index); + } + return obj; } @end @@ -764,11 +762,11 @@ static NSMapTable globalClassMap = 0; count = [_objects count]; GSIArrayInitWithZoneAndCapacity(_objMap, _zone, count); // Add marker for nil object - GSIArrayAddItem(_objMap, (GSIArrayItem)(void*)[NSNull null]); + GSIArrayAddItem(_objMap, (GSIArrayItem)[NSNull null]); // Add markers for unencoded objects. for (i = 1; i < count; i++) { - GSIArrayAddItem(_objMap, (GSIArrayItem)(void*)0); + GSIArrayAddItem(_objMap, (GSIArrayItem)nil); } } }