diff options
author | ferrieux <ferrieux@users.sourceforge.net> | 2012-12-22 19:05:34 (GMT) |
---|---|---|
committer | ferrieux <ferrieux@users.sourceforge.net> | 2012-12-22 19:05:34 (GMT) |
commit | a40590fd31db326000458a35d4bff19a8f7a3b4d (patch) | |
tree | a2f6ec0e2a2037ff55e2d98ba093a9fb64b5d77b | |
parent | f87e7cdade0bf88329c0502b62047b06a645b264 (diff) | |
download | tcl-a40590fd31db326000458a35d4bff19a8f7a3b4d.zip tcl-a40590fd31db326000458a35d4bff19a8f7a3b4d.tar.gz tcl-a40590fd31db326000458a35d4bff19a8f7a3b4d.tar.bz2 |
Stop leaking allocated space when objifying a zero-length DString. [Bug 3598150] spotted by afredd.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | generic/tclUtil.c | 18 |
2 files changed, 15 insertions, 8 deletions
@@ -1,3 +1,8 @@ +2012-12-22 Alexandre Ferrieux <ferrieux@users.sourceforge.net> + + * generic/tclUtil.c: Stop leaking allocated space when objifying a + zero-length DString. [Bug 3598150] spotted by afredd. + 2012-12-21 Jan Nijtmans <nijtmans@users.sf.net> * unix/dltest/pkgb.c: Inline compat Tcl_GetDefaultEncodingDir. diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 13e54ec..ddf067b 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -2927,14 +2927,16 @@ TclDStringToObj( { Tcl_Obj *result; - if (dsPtr->length == 0) { - TclNewObj(result); - } else if (dsPtr->string == dsPtr->staticSpace) { - /* - * Static buffer, so must copy. - */ - - TclNewStringObj(result, dsPtr->string, dsPtr->length); + if (dsPtr->string == dsPtr->staticSpace) { + if (dsPtr->length == 0) { + TclNewObj(result); + } else { + /* + * Static buffer, so must copy. + */ + + TclNewStringObj(result, dsPtr->string, dsPtr->length); + } } else { /* * Dynamic buffer, so transfer ownership and reset. |