From fea176b546ca6e85dee5c88887a9e3de9321ac76 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Wed, 18 Jun 2025 18:12:18 +0000 Subject: Start on [e8b18d7b1f] fix. --- generic/tclCmdAH.c | 46 +++++++++++++++++++++++++--------------------- 1 file 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; } -- cgit v0.12