mirror of
https://github.com/zebrajr/opencv.git
synced 2025-12-06 12:19:50 +01:00
Merge pull request #27738 from arrzhev:fix_memoryleak_pybindings
Fix memory leaks in pybindings
This commit is contained in:
commit
3a21ed56e3
|
|
@ -267,10 +267,12 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
|
|||
const int sz2 = 4; // Scalar has 4 elements.
|
||||
m = Mat::zeros(sz2, 1, CV_64F);
|
||||
|
||||
// Fill the Mat with array elements
|
||||
bool filled = true;
|
||||
const char *base_ptr = PyArray_BYTES(oarr);
|
||||
for(int i = 0; i < sz; i++ )
|
||||
for(int i = 0; i < sz && filled; i++ )
|
||||
{
|
||||
PyObject* oi = PyArray_GETITEM(oarr, base_ptr + step[0] * i);
|
||||
PyObject* oi = PyArray_GETITEM(oarr, base_ptr + step[0] * i); // new object
|
||||
if( PyInt_Check(oi) )
|
||||
m.at<double>(i) = (double)PyInt_AsLong(oi);
|
||||
else if( PyFloat_Check(oi) )
|
||||
|
|
@ -279,10 +281,16 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
|
|||
{
|
||||
failmsg("%s has some non-numerical elements", info.name);
|
||||
m.release();
|
||||
return false;
|
||||
filled = false;
|
||||
}
|
||||
|
||||
Py_DECREF(oi);
|
||||
}
|
||||
return true;
|
||||
|
||||
if(needcopy)
|
||||
Py_DECREF(o);
|
||||
|
||||
return filled;
|
||||
}
|
||||
|
||||
// handle degenerate case
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user