summaryrefslogtreecommitdiffstats
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
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.
-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.