summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclUtil.c18
2 files changed, 15 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 336da37..49da827 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.