summaryrefslogtreecommitdiffstats
path: root/generic/tclListObj.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-12-27 14:57:32 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-12-27 14:57:32 (GMT)
commit78d91cb25398a571e59790e8ba63206f8a6372ea (patch)
tree30f9805cad842d36d4e5474c555a4248fc2364db /generic/tclListObj.c
parent4b67a9506ba46713d3d2c88962ec1efef7325576 (diff)
parent66c29096944ef5a69468c0fd188382deadcb0e03 (diff)
downloadtcl-78d91cb25398a571e59790e8ba63206f8a6372ea.zip
tcl-78d91cb25398a571e59790e8ba63206f8a6372ea.tar.gz
tcl-78d91cb25398a571e59790e8ba63206f8a6372ea.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 17aa256..1166759 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -857,6 +857,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;
@@ -964,14 +968,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]);
}
/*