Browse Source

* don't increase refcounts for variants assigned to (ti_)const nodes, fixes
memory leak after r34288 and should have been done as part of r34287
(mantis #30546)

git-svn-id: trunk@34440 -

Jonas Maebe 9 years ago
parent
commit
2d051f89f7
3 changed files with 39 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 1 0
      compiler/nld.pas
  3. 37 0
      tests/test/units/variants/tw30546.pp

+ 1 - 0
.gitattributes

@@ -13399,6 +13399,7 @@ tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
 tests/test/units/variants/tvararrayofintf.pp svneol=native#text/plain
 tests/test/units/variants/tw26370.pp svneol=native#text/plain
 tests/test/units/variants/tw27044.pp svneol=native#text/plain
+tests/test/units/variants/tw30546.pp svneol=native#text/plain
 tests/test/units/windows/twinrawinput32.pp svneol=native#text/plain
 tests/test/units/windows/twinrawinput64.pp svneol=native#text/plain
 tests/test/uobjc24.pp svneol=native#text/plain

+ 1 - 0
compiler/nld.pas

@@ -836,6 +836,7 @@ implementation
         { call helpers for variant, they can contain non ref. counted types like
           vararrays which must be really copied }
         else if (left.resultdef.typ=variantdef) and
+            not(is_const(left)) and
             not(target_info.system in systems_garbage_collected_managed_types)  then
          begin
            { remove property flag to avoid errors, see comments for }

+ 37 - 0
tests/test/units/variants/tw30546.pp

@@ -0,0 +1,37 @@
+{ %opt=-gh }
+
+{$mode objfpc}
+{$h+}
+{$inline on}
+
+uses
+  variants;
+var
+  vv: variant;
+
+function func: variant; inline;
+begin
+  result:=vv;
+end;
+
+function varconstinl(const v: variant): boolean; inline;
+begin
+  result:=v='abc';
+end;
+
+function test: boolean; inline;
+begin
+  result:=varconstinl(func);
+end;
+
+procedure dotest;
+begin
+  HaltOnNotReleased:=true;
+  vv:='abc';
+  if not test then
+    halt(1);
+end;
+
+begin
+  dotest;
+end.