@@ -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 ;
0 commit comments