From d0c75cd790ce8b1eca79489c006dad5d530dc405 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Sun, 31 Jul 2022 18:12:51 +1000 Subject: 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 --- jim.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'jim.c') 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 -- cgit v1.1