Browse Source

* Fix memleak

git-svn-id: trunk@46413 -
michael 5 years ago
parent
commit
afcc7e0090
1 changed files with 11 additions and 2 deletions
  1. 11 2
      packages/fcl-json/src/jsonparser.pp

+ 11 - 2
packages/fcl-json/src/jsonparser.pp

@@ -129,8 +129,17 @@ begin
   // Add to existing structural type
   if (FStruct is TJSONObject) then
     begin
-    if (Not (joIgnoreDuplicates in options)) or  (TJSONObject(FStruct).IndexOfName(FKey)=-1) then
-      TJSONObject(FStruct).Add(FKey,AValue);
+    if (Not (joIgnoreDuplicates in options)) then
+      try
+        TJSONObject(FStruct).Add(FKey,AValue);
+      except
+        AValue.Free;
+        Raise;
+      end
+    else if (TJSONObject(FStruct).IndexOfName(FKey)=-1) then
+      TJSONObject(FStruct).Add(FKey,AValue)
+    else
+      AValue.Free;
     FKey:='';
     end
   else if (FStruct is TJSONArray) then