Skip to content

Commit 1f96bda

Browse files
Merge branch 'philippe/fix-320' into philippe/fix-320-changes
2 parents a06faef + 3c1ced2 commit 1f96bda

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/PyDictProxyHandler.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ bool PyDictProxyHandler::set(JSContext *cx, JS::HandleObject proxy, JS::HandleId
6868
PyObject *attrName = idToKey(cx, id);
6969

7070
PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
71-
if (PyDict_SetItem(self, attrName, pyTypeFactory(cx, rootedV))) {
71+
PyObject *value = pyTypeFactory(cx, rootedV);
72+
if (PyDict_SetItem(self, attrName, value)) {
73+
Py_DECREF(value);
7274
return result.failCantSetInterposed(); // raises JS exception
7375
}
76+
Py_DECREF(value);
7477
return result.succeed();
7578
}
7679

src/PyListProxyHandler.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static bool makeNewPyMethod(JSContext *cx, JS::MutableHandleValue function, JS::
4747
thisValue.setObject(*thisObject);
4848
PyObject *newSelf = pyTypeFactory(cx, thisValue);
4949
function.set(jsTypeFactory(cx, PyMethod_New(func, newSelf)));
50+
Py_DECREF(newSelf);
5051

5152
return true;
5253
}
@@ -111,9 +112,12 @@ static bool array_push(JSContext *cx, unsigned argc, JS::Value *vp) { // surely
111112
JS::RootedValue elementVal(cx);
112113
for (unsigned index = 0; index < numArgs; index++) {
113114
elementVal.set(args[index].get());
114-
if (PyList_Append(self, pyTypeFactory(cx, elementVal)) < 0) {
115+
PyObject *value = pyTypeFactory(cx, elementVal);
116+
if (PyList_Append(self, value) < 0) {
117+
Py_DECREF(value);
115118
return false;
116119
}
120+
Py_DECREF(value);
117121
}
118122

119123
args.rval().setInt32(PyList_GET_SIZE(self));
@@ -160,9 +164,12 @@ static bool array_unshift(JSContext *cx, unsigned argc, JS::Value *vp) { // sure
160164
JS::RootedValue elementVal(cx);
161165
for (int index = args.length() - 1; index >= 0; index--) {
162166
elementVal.set(args[index].get());
163-
if (PyList_Insert(self, 0, pyTypeFactory(cx, elementVal)) < 0) {
167+
PyObject *value = pyTypeFactory(cx, elementVal);
168+
if (PyList_Insert(self, 0, value) < 0) {
169+
Py_DECREF(value);
164170
return false;
165171
}
172+
Py_DECREF(value);
166173
}
167174

168175
args.rval().setInt32(PyList_GET_SIZE(self));
@@ -272,7 +279,9 @@ static bool array_indexOf(JSContext *cx, unsigned argc, JS::Value *vp) {
272279
}
273280

274281
JS::RootedValue elementVal(cx, args[0].get());
275-
PyObject *result = PyObject_CallMethod(self, "index", "Oi", pyTypeFactory(cx, elementVal), start);
282+
PyObject *value = pyTypeFactory(cx, elementVal);
283+
PyObject *result = PyObject_CallMethod(self, "index", "Oi", value, start);
284+
Py_DECREF(value);
276285

277286
if (!result) {
278287
PyErr_Clear();
@@ -353,9 +362,12 @@ static bool array_splice(JSContext *cx, unsigned argc, JS::Value *vp) {
353362
JS::RootedValue elementVal(cx);
354363
for (int index = 0; index < insertCount; index++) {
355364
elementVal.set(args[index + 2].get());
356-
if (PyList_SetItem(inserted, index, pyTypeFactory(cx, elementVal)) < 0) {
365+
PyObject *value = pyTypeFactory(cx, elementVal);
366+
if (PyList_SetItem(inserted, index, value) < 0) {
367+
Py_DECREF(value);
357368
return false;
358369
}
370+
Py_DECREF(value);
359371
}
360372

361373
if (PyList_SetSlice(self, actualStart, actualStart + actualDeleteCount, inserted) < 0) {

0 commit comments

Comments
 (0)