summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorferrieux <ferrieux@users.sourceforge.net>2012-12-22 19:05:34 (GMT)
committerferrieux <ferrieux@users.sourceforge.net>2012-12-22 19:05:34 (GMT)
commita40590fd31db326000458a35d4bff19a8f7a3b4d (patch)
treea2f6ec0e2a2037ff55e2d98ba093a9fb64b5d77b /generic
parentf87e7cdade0bf88329c0502b62047b06a645b264 (diff)
downloadtcl-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.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclUtil.c18
1 files changed, 10 insertions, 8 deletions
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.