Skip to content

Commit

Permalink
Fix bug when calling ref finalizers
Browse files Browse the repository at this point in the history
Commit 21d7fc3 introduced a bug where the finalizer was freed too early

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information
msteveb committed Dec 16, 2011
1 parent 939bd44 commit 535ce8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jim.c
Original file line number Diff line number Diff line change
Expand Up @@ -5173,6 +5173,8 @@ int Jim_Collect(Jim_Interp *interp)
objv[2] = refPtr->objPtr;

/* Drop the reference itself */
/* Avoid the finaliser being freed here */
Jim_IncrRefCount(objv[0]);
Jim_DeleteHashEntry(&interp->references, refId);

/* Call the finalizer. Errors ignored. */
Expand All @@ -5181,6 +5183,8 @@ int Jim_Collect(Jim_Interp *interp)
Jim_EvalObjVector(interp, 3, objv);
Jim_SetResult(interp, oldResult);
Jim_DecrRefCount(interp, oldResult);

Jim_DecrRefCount(interp, objv[0]);
}
else {
Jim_DeleteHashEntry(&interp->references, refId);
Expand Down
8 changes: 8 additions & 0 deletions regtest.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ catch {
} msg
puts "TEST 27 PASSED"

# REGTEST 28
# 16 Dec 2011 - ref count problem with finalizers
catch {
ref x x [list dummy]
collect
}
puts "TEST 28 PASSED"

# TAKE THE FOLLOWING puts AS LAST LINE

puts "--- ALL TESTS PASSED ---"

0 comments on commit 535ce8f

Please sign in to comment.