Skip to content

Commit 0eeda35

Browse files
committed
fix: properly handle the reference count when doing list.concat()
`PyList_SetItem` steals the reference, so we must increase the reference count by 1
1 parent 8e365a7 commit 0eeda35

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/PyListProxyHandler.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,11 @@ static bool array_concat(JSContext *cx, unsigned argc, JS::Value *vp) {
553553

554554
PyObject *result = PyList_New(selfSize);
555555

556+
// Copy items to the new list
556557
for (Py_ssize_t index = 0; index < selfSize; index++) {
557-
PyList_SetItem(result, index, PyList_GetItem(self, index));
558+
PyObject *item = PyList_GetItem(self, index);
559+
Py_INCREF(item); // `PyList_SetItem` steals the reference, so we must increase the reference count by 1
560+
PyList_SetItem(result, index, item);
558561
}
559562

560563
unsigned numArgs = args.length();

0 commit comments

Comments
 (0)