Skip to content

Commit

Permalink
Merge pull request opencv#23350 from spikethehobbitmage:4.x
Browse files Browse the repository at this point in the history
Fix reference counting errors in registerNewType
  • Loading branch information
asmorkalov authored Apr 3, 2023
2 parents 3ac06bf + 95f087c commit 66a5ecb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/python/src2/cv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ static bool init_submodule(PyObject * root, const char * name, PyMethodDef * met
static inline
bool registerTypeInModuleScope(PyObject* module, const char* type_name, PyObject* type_obj)
{
Py_INCREF(type_obj); /// Give PyModule_AddObject a reference to steal.
if (PyModule_AddObject(module, type_name, type_obj) < 0)
{
PyErr_Format(PyExc_ImportError,
Expand Down
2 changes: 2 additions & 0 deletions modules/python/src2/pycompat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,10 @@ PyObject* pyopencv_from(const TYPE& src)
if (!registerNewType(m, #EXPORT_NAME, (PyObject*)pyopencv_##CLASS_ID##_TypePtr, SCOPE)) \
{ \
printf("Failed to register a new type: " #EXPORT_NAME ", base (" #BASE ") in " SCOPE " \n"); \
Py_DECREF(pyopencv_##CLASS_ID##_TypePtr); \
ERROR_HANDLER; \
} \
Py_DECREF(pyopencv_##CLASS_ID##_TypePtr); \
}

// Debug module load:
Expand Down

0 comments on commit 66a5ecb

Please sign in to comment.