andrea-magni / MARS

MARS-Curiosity Delphi REST Library
Mozilla Public License 2.0
363 stars 112 forks source link

Memory leak in TJSONObjectHelper.WriteStringValue #122

Closed andrea-magni closed 2 years ago

andrea-magni commented 2 years ago

A memory leak of TPair value occurs if WriteStringValue is called twice (or more) with the same key.

To Reproduce

var
  LObj: TJSONObject;
begin
  LObj := TJSONObject.Create;
  try
    LObj.WriteStringValue('Name1', 'Value 1');
    LObj.WriteStringValue('Name2', 'Value 2');
    LObj.WriteStringValue('Name3', 'Value 3');

    LObj.WriteStringValue('Name1', 'Value 4');  // causa memory leak!
  finally
    FreeAndNil(LObj);
  end;
end;

Thanks to @Brov84 for pointing this out.

Brov84 commented 2 years ago

Thank you @andrea-magni