Skip to content

Commit f27780d

Browse files
xdecref not decref
1 parent 0eb54c6 commit f27780d

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/PyListProxyHandler.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +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);
50+
Py_XDECREF(newSelf);
5151

5252
return true;
5353
}
@@ -114,10 +114,10 @@ static bool array_push(JSContext *cx, unsigned argc, JS::Value *vp) { // surely
114114
elementVal.set(args[index].get());
115115
PyObject *value = pyTypeFactory(cx, elementVal);
116116
if (PyList_Append(self, value) < 0) {
117-
Py_DECREF(value);
117+
Py_XDECREF(value);
118118
return false;
119119
}
120-
Py_DECREF(value);
120+
Py_XDECREF(value);
121121
}
122122

123123
args.rval().setInt32(PyList_GET_SIZE(self));
@@ -166,10 +166,10 @@ static bool array_unshift(JSContext *cx, unsigned argc, JS::Value *vp) { // sure
166166
elementVal.set(args[index].get());
167167
PyObject *value = pyTypeFactory(cx, elementVal);
168168
if (PyList_Insert(self, 0, value) < 0) {
169-
Py_DECREF(value);
169+
Py_XDECREF(value);
170170
return false;
171171
}
172-
Py_DECREF(value);
172+
Py_XDECREF(value);
173173
}
174174

175175
args.rval().setInt32(PyList_GET_SIZE(self));
@@ -281,7 +281,7 @@ static bool array_indexOf(JSContext *cx, unsigned argc, JS::Value *vp) {
281281
JS::RootedValue elementVal(cx, args[0].get());
282282
PyObject *value = pyTypeFactory(cx, elementVal);
283283
PyObject *result = PyObject_CallMethod(self, "index", "Oi", value, start);
284-
Py_DECREF(value);
284+
Py_XDECREF(value);
285285

286286
if (!result) {
287287
PyErr_Clear();
@@ -364,10 +364,8 @@ static bool array_splice(JSContext *cx, unsigned argc, JS::Value *vp) {
364364
elementVal.set(args[index + 2].get());
365365
PyObject *value = pyTypeFactory(cx, elementVal);
366366
if (PyList_SetItem(inserted, index, value) < 0) {
367-
Py_DECREF(value);
368367
return false;
369368
}
370-
Py_DECREF(value);
371369
}
372370

373371
if (PyList_SetSlice(self, actualStart, actualStart + actualDeleteCount, inserted) < 0) {
@@ -430,12 +428,18 @@ static bool array_fill(JSContext *cx, unsigned argc, JS::Value *vp) {
430428

431429
JS::RootedValue fillValue(cx, args[0].get());
432430
PyObject *fillValueItem = pyTypeFactory(cx, fillValue);
431+
bool setItemCalled = false;
433432
for (int index = actualStart; index < actualEnd; index++) {
433+
setItemCalled = true;
434434
if (PyList_SetItem(self, index, fillValueItem) < 0) {
435435
return false;
436436
}
437437
}
438438

439+
if (!setItemCalled) {
440+
Py_XDECREF(fillValueItem);
441+
}
442+
439443
// return ref to self
440444
args.rval().set(jsTypeFactory(cx, self));
441445
return true;

src/PyObjectProxyHandler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ bool PyObjectProxyHandler::set(JSContext *cx, JS::HandleObject proxy, JS::Handle
176176
PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
177177
PyObject *value = pyTypeFactory(cx, rootedV);
178178
if (PyObject_SetAttr(self, attrName, value)) {
179-
Py_DECREF(value);
179+
Py_XDECREF(value);
180180
return result.failCantSetInterposed(); // raises JS exception
181181
}
182-
Py_DECREF(value);
182+
Py_XDECREF(value);
183183
return result.succeed();
184184
}
185185

src/internalBinding/timers.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static bool enqueueWithDelay(JSContext *cx, unsigned argc, JS::Value *vp) {
3232
PyEventLoop loop = PyEventLoop::getRunningLoop();
3333
if (!loop.initialized()) return false;
3434
PyEventLoop::AsyncHandle::id_t handleId = loop.enqueueWithDelay(job, delaySeconds, repeat);
35-
Py_DECREF(job);
35+
Py_XDECREF(job);
3636

3737
// Return the `timeoutID` to use in `clearTimeout`
3838
args.rval().setNumber(handleId);

0 commit comments

Comments
 (0)