Browse Source

Fix `Collection.GetItemByJSON()` method mishandling reference counting

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
6a0c8ba5ee
  1. 22
      sources/Data/Collections/Collection.uc

22
sources/Data/Collections/Collection.uc

@ -97,9 +97,15 @@ public final function AcediaObject GetItemByJSON(JSONPointer jsonPointer)
local Text nextSegment; local Text nextSegment;
local AcediaObject result, nextObject; local AcediaObject result, nextObject;
local Collection prevCollection, nextCollection; local Collection prevCollection, nextCollection;
if (jsonPointer == none) return none;
if (jsonPointer.GetLength() < 1) return self;
if (jsonPointer == none) {
return none;
}
if (jsonPointer.GetLength() < 1)
{
NewRef();
return self;
}
nextCollection = self; nextCollection = self;
nextCollection.NewRef(); nextCollection.NewRef();
while (segmentIndex < jsonPointer.GetLength() - 1) while (segmentIndex < jsonPointer.GetLength() - 1)
@ -124,7 +130,6 @@ public final function AcediaObject GetItemByJSON(JSONPointer jsonPointer)
result = nextCollection.GetByText(nextSegment); result = nextCollection.GetByText(nextSegment);
_.memory.Free(nextSegment); _.memory.Free(nextSegment);
} }
_.memory.Free(jsonPointer);
return result; return result;
} }
@ -167,9 +172,14 @@ public final function AcediaObject GetItemBy(BaseText jsonPointerAsText)
{ {
local AcediaObject result; local AcediaObject result;
local JSONPointer jsonPointer; local JSONPointer jsonPointer;
if (jsonPointerAsText == none) return none; if (jsonPointerAsText == none) {
if (jsonPointerAsText.IsEmpty()) return self; return none;
}
if (jsonPointerAsText.IsEmpty())
{
NewRef();
return self;
}
jsonPointer = _.json.Pointer(jsonPointerAsText); jsonPointer = _.json.Pointer(jsonPointerAsText);
result = GetItemByJSON(jsonPointer); result = GetItemByJSON(jsonPointer);
_.memory.Free(jsonPointer); _.memory.Free(jsonPointer);

Loading…
Cancel
Save