Skip to content

Commit 7d1f0c7

Browse files
author
bzbarsky%mit.edu
committed
Make ReplaceObjectAt a little safer. Bug 227780, r=timeless, sr=alecf
1 parent a39d4b7 commit 7d1f0c7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

xpcom/ds/nsCOMArray.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex)
115115
// ReplaceElementAt could fail, such as if the array grows
116116
// so only release the existing object if the replacement succeeded
117117
if (result) {
118-
NS_IF_RELEASE(oldObject);
118+
// Make sure to addref first, in case aObject == oldObject
119119
NS_IF_ADDREF(aObject);
120+
NS_IF_RELEASE(oldObject);
120121
}
121122
return result;
122123
}

0 commit comments

Comments
 (0)