From bb15754427b42b7030fca0294e466e1aad46c335 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 21 Apr 2015 10:05:38 -0500 Subject: [PATCH] BIT-1373: fix vector index assignment ref count bug. --- src/Val.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 7c83830bf9..f3825dc9da 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2985,8 +2985,10 @@ bool VectorVal::Assign(unsigned int index, Val* element, Opcode op) } } + Val* val_at_index = 0; + if ( index < val.vector_val->size() ) - Unref((*val.vector_val)[index]); + val_at_index = (*val.vector_val)[index]; else val.vector_val->resize(index + 1); @@ -2999,10 +3001,12 @@ bool VectorVal::Assign(unsigned int index, Val* element, Opcode op) StateAccess::Log(new StateAccess(op == OP_INCR ? OP_INCR_IDX : OP_ASSIGN_IDX, - this, ival, element, (*val.vector_val)[index])); + this, ival, element, val_at_index)); Unref(ival); } + Unref(val_at_index); + // Note: we do *not* Ref() the element, if any, at this point. // AssignExpr::Eval() already does this; other callers must remember // to do it similarly.