summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2025-06-20 16:00:23 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2025-06-20 16:00:23 (GMT)
commitf1a3e189ecdffa6abfd80b30b12d268eb75632b3 (patch)
tree11c36b2635ac9b608721eb3d48dc6f28a6102aa3
parent19591e2473f1e18616de5f407e943acefbac163e (diff)
parentfea176b546ca6e85dee5c88887a9e3de9321ac76 (diff)
downloadtcl-f1a3e189ecdffa6abfd80b30b12d268eb75632b3.zip
tcl-f1a3e189ecdffa6abfd80b30b12d268eb75632b3.tar.gz
tcl-f1a3e189ecdffa6abfd80b30b12d268eb75632b3.tar.bz2
Fix [e8b18d7b1f] - release encodings on error
-rw-r--r--generic/tclCmdAH.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 673b4f8..59a30d2 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -551,14 +551,14 @@ EncodingConvertfromObjCmd(
result = Tcl_ExternalToUtfDStringEx(interp, encoding, bytesPtr, length, flags,
&ds, failVarObj ? &errorLocation : NULL);
/* NOTE: ds must be freed beyond this point even on error */
+
switch (result) {
case TCL_OK:
errorLocation = TCL_INDEX_NONE;
break;
case TCL_ERROR:
/* Error in parameters. Should not happen. interp will have error */
- Tcl_DStringFree(&ds);
- return TCL_ERROR;
+ goto done;
default:
/*
* One of the TCL_CONVERT_* errors. If we were not interested in the
@@ -567,8 +567,8 @@ EncodingConvertfromObjCmd(
* what could be decoded and the returned error location.
*/
if (failVarObj == NULL) {
- Tcl_DStringFree(&ds);
- return TCL_ERROR;
+ result = TCL_ERROR;
+ goto done;
}
break;
}
@@ -582,8 +582,8 @@ EncodingConvertfromObjCmd(
TclNewIndexObj(failIndex, errorLocation);
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, failIndex,
TCL_LEAVE_ERR_MSG) == NULL) {
- Tcl_DStringFree(&ds);
- return TCL_ERROR;
+ result = TCL_ERROR;
+ goto done;
}
}
/*
@@ -592,12 +592,14 @@ EncodingConvertfromObjCmd(
*/
Tcl_SetObjResult(interp, Tcl_DStringToObj(&ds));
+ result = TCL_OK;
- /* We're done with the encoding */
-
- Tcl_FreeEncoding(encoding);
- return TCL_OK;
-
+done:
+ Tcl_DStringFree(&ds);
+ if (encoding) {
+ Tcl_FreeEncoding(encoding);
+ }
+ return result;
}
/*
@@ -651,8 +653,7 @@ EncodingConverttoObjCmd(
break;
case TCL_ERROR:
/* Error in parameters. Should not happen. interp will have error */
- Tcl_DStringFree(&ds);
- return TCL_ERROR;
+ goto done;
default:
/*
* One of the TCL_CONVERT_* errors. If we were not interested in the
@@ -661,8 +662,8 @@ EncodingConverttoObjCmd(
* what could be decoded and the returned error location.
*/
if (failVarObj == NULL) {
- Tcl_DStringFree(&ds);
- return TCL_ERROR;
+ result = TCL_ERROR;
+ goto done;
}
break;
}
@@ -676,20 +677,23 @@ EncodingConverttoObjCmd(
TclNewIndexObj(failIndex, errorLocation);
if (Tcl_ObjSetVar2(interp, failVarObj, NULL, failIndex,
TCL_LEAVE_ERR_MSG) == NULL) {
- Tcl_DStringFree(&ds);
- return TCL_ERROR;
+ result = TCL_ERROR;
+ goto done;
}
}
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(
(unsigned char*) Tcl_DStringValue(&ds),
Tcl_DStringLength(&ds)));
- Tcl_DStringFree(&ds);
- /* We're done with the encoding */
+ result = TCL_OK;
- Tcl_FreeEncoding(encoding);
- return TCL_OK;
+done:
+ Tcl_DStringFree(&ds);
+ if (encoding) {
+ Tcl_FreeEncoding(encoding);
+ }
+ return result;
}