summaryrefslogtreecommitdiffstats
path: root/generic/tclListObj.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-12-27 15:04:11 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-12-27 15:04:11 (GMT)
commitd12ee9da30592f7dd3121c17b48056fff83824dc (patch)
treef4ed0cc041f03fed34a2c8d4a5d5e5d78d461095 /generic/tclListObj.c
parent65013d771ad969f961573ee0219cbbb59e8fbb86 (diff)
parent78d91cb25398a571e59790e8ba63206f8a6372ea (diff)
downloadtcl-d12ee9da30592f7dd3121c17b48056fff83824dc.zip
tcl-d12ee9da30592f7dd3121c17b48056fff83824dc.tar.gz
tcl-d12ee9da30592f7dd3121c17b48056fff83824dc.tar.bz2
[Bug 3598580]: Tcl_ListObjReplace may release deleted elements too early
Diffstat (limited to 'generic/tclListObj.c')
-rw-r--r--generic/tclListObj.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index 3668b45..53c3f66 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -909,6 +909,10 @@ Tcl_ListObjReplace(
isShared = (listRepPtr->refCount > 1);
numRequired = numElems - count + objc;
+ for (i = 0; i < objc; i++) {
+ Tcl_IncrRefCount(objv[i]);
+ }
+
if ((numRequired <= listRepPtr->maxElemCount) && !isShared) {
int shift;
@@ -1027,14 +1031,11 @@ Tcl_ListObjReplace(
}
/*
- * Insert the new elements into elemPtrs before "first". We don't do a
- * memcpy here because we must increment the reference counts for the
- * added elements, so we must explicitly loop anyway.
+ * Insert the new elements into elemPtrs before "first".
*/
for (i=0,j=first ; i<objc ; i++,j++) {
elemPtrs[j] = objv[i];
- Tcl_IncrRefCount(objv[i]);
}
/*