Browse Source

* only set dynarray pointer to nil in decref in case the last reference
has been destroyed (mantis #12000)

git-svn-id: trunk@11672 -

Jonas Maebe 17 years ago
parent
commit
65f217ed02
3 changed files with 38 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 4 2
      rtl/inc/dynarr.inc
  3. 33 0
      tests/webtbs/tw12000.pp

+ 1 - 0
.gitattributes

@@ -8518,6 +8518,7 @@ tests/webtbs/tw11861.pp svneol=native#text/plain
 tests/webtbs/tw11862.pp svneol=native#text/plain
 tests/webtbs/tw11896.pp svneol=native#text/plain
 tests/webtbs/tw11937.pp svneol=native#text/plain
+tests/webtbs/tw12000.pp svneol=native#text/plain
 tests/webtbs/tw1203.pp svneol=native#text/plain
 tests/webtbs/tw1204.pp svneol=native#text/plain
 tests/webtbs/tw1207.pp svneol=native#text/plain

+ 4 - 2
rtl/inc/dynarr.inc

@@ -106,8 +106,10 @@ procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer); [Public,Alias:'FP
      { decr. ref. count }
      { should we remove the array? }
      if declocked(realp^.refcount) then
-       fpc_dynarray_clear_internal(realp,pdynarraytypeinfo(ti));
-     p := nil;
+       begin
+         fpc_dynarray_clear_internal(realp,pdynarraytypeinfo(ti));
+         p := nil;
+       end;
   end;
 
 { provide local access to dynarr_decr_ref for dynarr_setlength }

+ 33 - 0
tests/webtbs/tw12000.pp

@@ -0,0 +1,33 @@
+program arcrash;
+
+{$mode objfpc}{$H+}
+
+type
+  Trec = record
+    Signature: array of Integer;
+    s: ansistring;
+  end;
+
+var
+  M: array of Trec;
+  s2: ansistring;
+
+begin
+  SetLength(M,2);
+  SetLength(M[0].Signature,4);
+  SetLength(M[1].Signature,4);
+  setlength(m[0].s,2);
+  s2:=m[0].s;
+  WriteLn(Length(M[0].Signature), ' ', Length(M[1].Signature));
+  writeln(length(m[0].s));
+  M[0].Signature := M[0].Signature;
+  m[0].s:=m[0].s;
+  WriteLn(Length(M[0].Signature), ' ', Length(M[1].Signature));
+  writeln(length(m[0].s));
+  s2:='';
+  if (Length(M[0].Signature) <> 4) then
+    halt(1);
+  if (Length(M[0].s) <> 2) then
+    halt(2);
+end.
+