diff options
author | dgp <dgp@users.sourceforge.net> | 2018-04-05 16:37:35 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2018-04-05 16:37:35 (GMT) |
commit | 43507f353b82f414fff3810cc0d781a44e7ae3e9 (patch) | |
tree | 7946757201fa42a1b298f6006e4f17035158454d | |
parent | eb8817687f0753816e8308b93b3e992414afeca4 (diff) | |
download | tcl-43507f353b82f414fff3810cc0d781a44e7ae3e9.zip tcl-43507f353b82f414fff3810cc0d781a44e7ae3e9.tar.gz tcl-43507f353b82f414fff3810cc0d781a44e7ae3e9.tar.bz2 |
Plug memleak when [scan] raises an error.
-rw-r--r-- | generic/tclScan.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/generic/tclScan.c b/generic/tclScan.c index 113b4c6..0e3da17 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -941,11 +941,24 @@ Tcl_ScanObjCmd( } else if (flags & SCAN_BIG) { if (flags & SCAN_UNSIGNED) { mp_int big; - if ((Tcl_GetBignumFromObj(interp, objPtr, &big) != TCL_OK) - || mp_isneg(&big)) { + int code = Tcl_GetBignumFromObj(interp, objPtr, &big); + + if (code == TCL_OK) { + if (mp_isneg(&big)) { + code = TCL_ERROR; + } + mp_clear(&big); + } + + if (code == TCL_ERROR) { + if (objs != NULL) { + ckfree(objs); + } + Tcl_DecrRefCount(objPtr); Tcl_SetObjResult(interp, Tcl_NewStringObj( "unsigned bignum scans are invalid", -1)); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BADUNSIGNED",NULL); + Tcl_SetErrorCode(interp, "TCL", "FORMAT", + "BADUNSIGNED",NULL); return TCL_ERROR; } } |