aboutsummaryrefslogtreecommitdiff
path: root/jim.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2022-07-31 18:12:51 +1000
committerSteve Bennett <steveb@workware.net.au>2022-07-31 18:17:48 +1000
commitd0c75cd790ce8b1eca79489c006dad5d530dc405 (patch)
treead2202e6e66aded27ed34ea29326f537b6cf31d8 /jim.c
parent340d0a09b7b4ed64c00d86fa8076570627963059 (diff)
downloadjimtcl-d0c75cd790ce8b1eca79489c006dad5d530dc405.zip
jimtcl-d0c75cd790ce8b1eca79489c006dad5d530dc405.tar.gz
jimtcl-d0c75cd790ce8b1eca79489c006dad5d530dc405.tar.bz2
jim: fix sometimes overly zealous garbage collection
When checking for "weak" references where the only reference is in the command hash table, need to check the reference count of the key in the hash table (this is the command name), not the reference count of the object we are using to look up the command. Without this it is possible that a reference (typically a lambda) will be collected even though there is still a reference to it. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim.c')
-rw-r--r--jim.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/jim.c b/jim.c
index 893dff9..d6005d8 100644
--- a/jim.c
+++ b/jim.c
@@ -5527,11 +5527,14 @@ int Jim_Collect(Jim_Interp *interp)
/* But if this is a command in the command table with refCount 1
* don't mark it since it can be deleted.
*/
- if (p == str && objPtr->refCount == 1 && Jim_FindHashEntry(&interp->commands, objPtr)) {
+ if (p == str) {
+ Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, objPtr);
+ if (he && ((Jim_Obj *)Jim_GetHashEntryKey(he))->refCount == 1) {
#ifdef JIM_DEBUG_GC
- printf("No MARK: %lu - command with refcount=1\n", id);
+ printf("No MARK: %lu - command with refcount=1\n", idp);
#endif
- break;
+ break;
+ }
}
Jim_AddHashEntry(&marks, &id, objPtr);
#ifdef JIM_DEBUG_GC