Skip to content

Commit

Permalink
fix: properly handle the reference count when doing list.concat()
Browse files Browse the repository at this point in the history
`PyList_SetItem` steals the reference, so we must increase the reference count by 1
  • Loading branch information
Xmader committed Sep 24, 2024
1 parent 8e365a7 commit 0eeda35
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/PyListProxyHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,11 @@ static bool array_concat(JSContext *cx, unsigned argc, JS::Value *vp) {

PyObject *result = PyList_New(selfSize);

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

unsigned numArgs = args.length();
Expand Down

0 comments on commit 0eeda35

Please sign in to comment.