@@ -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