Fixed a retain/release problem.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19070 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-04-10 05:59:40 +00:00
parent 4aba1cd33e
commit ac23e1ba3c
2 changed files with 31 additions and 7 deletions

View file

@ -1,7 +1,14 @@
2004-04-09 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSUnarchiver.m: Retain objects while they are being
decoded. Fixes problem reported by Willem Rein Oudshoorn where
an object used by more than one object being decoded could be
released by one object before being used by the other.
2004-04-09 Willem Rein Oudshoorn <Wim.Oudshoorn@agilisys.com> 2004-04-09 Willem Rein Oudshoorn <Wim.Oudshoorn@agilisys.com>
* Source/NSTask.m ([NSConcreteWindowsTask -launch]): Set stdin/stdout/stderr * Source/NSTask.m ([NSConcreteWindowsTask -launch]): Set
file to values provided by the user (Fix #8417) stdin/stdout/stderr file to values provided by the user (Fix #8417)
2004-04-08 Adam Fedor <fedor@gnu.org> 2004-04-08 Adam Fedor <fedor@gnu.org>

View file

@ -395,8 +395,14 @@ static Class NSDataMallocClass;
if (clsMap) if (clsMap)
{ {
NSZone *z = clsMap->zone; NSZone *z = clsMap->zone;
unsigned i;
GSIArrayClear(clsMap); GSIArrayClear(clsMap);
i = GSIArrayCount(objMap);
while (i-- > 0)
{
RELEASE(GSIArrayItemAtIndex(objMap, i).obj);
}
GSIArrayClear(objMap); GSIArrayClear(objMap);
GSIArrayClear(ptrMap); GSIArrayClear(ptrMap);
NSZoneFree(z, (void*)clsMap); NSZoneFree(z, (void*)clsMap);
@ -594,19 +600,25 @@ static Class NSDataMallocClass;
format: @"decoded nil class"]; format: @"decoded nil class"];
} }
obj = [c allocWithZone: zone]; obj = [c allocWithZone: zone];
/*
* The objMap array does not retain its contents directly,
* so we perform explicit retain/release as we add objects
* to and remove objects from the array.
*/
RETAIN(obj);
GSIArrayAddItem(objMap, (GSIArrayItem)obj); GSIArrayAddItem(objMap, (GSIArrayItem)obj);
rep = [obj initWithCoder: self]; rep = [obj initWithCoder: self];
if (rep != obj) if (rep != obj)
{ {
obj = rep; ASSIGN(obj, rep);
GSIArraySetItemAtIndex(objMap, (GSIArrayItem)obj, xref); GSIArraySetItemAtIndex(objMap, (GSIArrayItem)obj, xref);
} }
rep = [obj awakeAfterUsingCoder: self]; rep = [obj awakeAfterUsingCoder: self];
if (rep != obj) if (rep != obj)
{ {
obj = rep; ASSIGN(obj, rep);
GSIArraySetItemAtIndex(objMap, (GSIArrayItem)obj, xref); GSIArraySetItemAtIndex(objMap, (GSIArrayItem)obj, xref);
} }
} }
@ -1161,11 +1173,16 @@ static Class NSDataMallocClass;
if (replacement == anObject) if (replacement == anObject)
return; return;
for (i = GSIArrayCount(objMap) - 1; i > 0; i--) i = GSIArrayCount(objMap);
while (i-- > 0)
{ {
if (GSIArrayItemAtIndex(objMap, i).obj == anObject) id old = GSIArrayItemAtIndex(objMap, i).obj;
if (old == anObject)
{ {
GSIArraySetItemAtIndex(objMap, (GSIArrayItem)replacement, i); GSIArraySetItemAtIndex(objMap, (GSIArrayItem)replacement, i);
RETAIN(replacement);
RELEASE(old);
return; return;
} }
} }
@ -1255,7 +1272,7 @@ static Class NSDataMallocClass;
objMap = &clsMap[1]; objMap = &clsMap[1];
GSIArrayInitWithZoneAndCapacity(objMap, zone, sizeO); GSIArrayInitWithZoneAndCapacity(objMap, zone, sizeO);
GSIArrayAddItem(objMap, (GSIArrayItem)(void*)0); GSIArrayAddItem(objMap, (GSIArrayItem)(void*)nil);
ptrMap = &clsMap[2]; ptrMap = &clsMap[2];
GSIArrayInitWithZoneAndCapacity(ptrMap, zone, sizeP); GSIArrayInitWithZoneAndCapacity(ptrMap, zone, sizeP);