summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2021-04-25 13:58:22 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2021-04-25 13:58:22 (GMT)
commitc1cc3a72382efe93780f665b571785402f056366 (patch)
tree46de5bfce2a14823df9e480c636ee8eba27d7779 /generic/tclIO.c
parent4aa680d80d061bebaf17ae938a541d6caff522cf (diff)
downloadtcl-c1cc3a72382efe93780f665b571785402f056366.zip
tcl-c1cc3a72382efe93780f665b571785402f056366.tar.gz
tcl-c1cc3a72382efe93780f665b571785402f056366.tar.bz2
Documenting our reference count management
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 3954af2..fd87520 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -10966,15 +10966,17 @@ Tcl_SetChannelErrorInterp(
Tcl_Obj *msg) /* Error message to store. */
{
Interp *iPtr = (Interp *) interp;
-
- if (iPtr->chanMsg != NULL) {
- TclDecrRefCount(iPtr->chanMsg);
- iPtr->chanMsg = NULL;
- }
+ Tcl_Obj *disposePtr = iPtr->chanMsg;
if (msg != NULL) {
iPtr->chanMsg = FixLevelCode(msg);
Tcl_IncrRefCount(iPtr->chanMsg);
+ } else {
+ iPtr->chanMsg = NULL;
+ }
+
+ if (disposePtr != NULL) {
+ TclDecrRefCount(disposePtr);
}
return;
}
@@ -11002,15 +11004,17 @@ Tcl_SetChannelError(
Tcl_Obj *msg) /* Error message to store. */
{
ChannelState *statePtr = ((Channel *) chan)->state;
-
- if (statePtr->chanMsg != NULL) {
- TclDecrRefCount(statePtr->chanMsg);
- statePtr->chanMsg = NULL;
- }
+ Tcl_Obj *disposePtr = statePtr->chanMsg;
if (msg != NULL) {
statePtr->chanMsg = FixLevelCode(msg);
Tcl_IncrRefCount(statePtr->chanMsg);
+ } else {
+ statePtr->chanMsg = NULL;
+ }
+
+ if (disposePtr != NULL) {
+ TclDecrRefCount(disposePtr);
}
return;
}