aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2024-09-04 14:52:31 +1000
committerSteve Bennett <steveb@workware.net.au>2024-09-20 11:20:34 +1000
commitaea59d5f9b068a12eaa47451ad0fe6a3e9eeb5d5 (patch)
tree3b8a5d5340b21adb1f3076e18ccf52864ab50afc
parent04faf00753541dd414074e7589d92e93d765f034 (diff)
downloadjimtcl-aea59d5f9b068a12eaa47451ad0fe6a3e9eeb5d5.zip
jimtcl-aea59d5f9b068a12eaa47451ad0fe6a3e9eeb5d5.tar.gz
jimtcl-aea59d5f9b068a12eaa47451ad0fe6a3e9eeb5d5.tar.bz2
aio: fix rare refcount error in maintainer mode
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-aio.c9
-rw-r--r--regtest.tcl7
2 files changed, 16 insertions, 0 deletions
diff --git a/jim-aio.c b/jim-aio.c
index e25af18..0f150b5 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -1170,6 +1170,15 @@ static int aio_cmd_puts(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
/* Keep it simple and always go via the writebuf instead of trying to optimise
* the case that we can write immediately
*/
+#ifdef JIM_MAINTAINER
+ if (Jim_IsShared(af->writebuf)) {
+ /* This should generally never happen since this object isn't accessible,
+ * but it is possible with 'debug objects' */
+ Jim_DecrRefCount(interp, af->writebuf);
+ af->writebuf = Jim_DuplicateObj(interp, af->writebuf);
+ Jim_IncrRefCount(af->writebuf);
+ }
+#endif
Jim_AppendObj(interp, af->writebuf, strObj);
if (nl) {
Jim_AppendString(interp, af->writebuf, "\n", 1);
diff --git a/regtest.tcl b/regtest.tcl
index 5e66aa3..99a65fe 100644
--- a/regtest.tcl
+++ b/regtest.tcl
@@ -399,6 +399,13 @@ set json {
catch {json::decode $json}
puts "TEST 56 PASSED"
+if {[exists -command debug]} {
+ set f [open /dev/null w]
+ $f puts [debug objects]
+ $f close
+}
+puts "TEST 57 PASSED"
+
# TAKE THE FOLLOWING puts AS LAST LINE
puts "--- ALL TESTS PASSED ---"