From 3045c6904fbbf2efbecbd14d40a120b9e9f7ee68 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sun, 3 Jul 2022 00:12:38 +0700 Subject: [PATCH] Fix `Set...()` methods leaking memory in ArrayList --- sources/Data/Collections/ArrayList.uc | 32 ++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/sources/Data/Collections/ArrayList.uc b/sources/Data/Collections/ArrayList.uc index 733e24c..2fd58f1 100644 --- a/sources/Data/Collections/ArrayList.uc +++ b/sources/Data/Collections/ArrayList.uc @@ -518,12 +518,16 @@ public final function ArrayList SetBool( bool value, optional bool asRef) { + local AcediaObject newValue; + if (asRef) { - SetItem(index, _.ref.bool(value)); + newValue = _.ref.bool(value); } else { - SetItem(index, _.box.bool(value)); + newValue = _.box.bool(value); } + SetItem(index, newValue); + newValue.FreeSelf(); return self; } @@ -581,12 +585,16 @@ public final function ArrayList SetByte( byte value, optional bool asRef) { + local AcediaObject newValue; + if (asRef) { - SetItem(index, _.ref.byte(value)); + newValue = _.ref.byte(value); } else { - SetItem(index, _.box.byte(value)); + newValue = _.box.byte(value); } + SetItem(index, newValue); + newValue.FreeSelf(); return self; } @@ -644,12 +652,16 @@ public final function ArrayList SetInt( int value, optional bool asRef) { + local AcediaObject newValue; + if (asRef) { - SetItem(index, _.ref.int(value)); + newValue = _.ref.int(value); } else { - SetItem(index, _.box.int(value)); + newValue = _.box.int(value); } + SetItem(index, newValue); + newValue.FreeSelf(); return self; } @@ -707,12 +719,16 @@ public final function ArrayList SetFloat( float value, optional bool asRef) { + local AcediaObject newValue; + if (asRef) { - SetItem(index, _.ref.float(value)); + newValue = _.ref.float(value); } else { - SetItem(index, _.box.float(value)); + newValue = _.box.float(value); } + SetItem(index, newValue); + newValue.FreeSelf(); return self; }