Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
[fix]Modified reference counting to prevent memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperG1998 committed Apr 12, 2022
1 parent f5b0aae commit 1a0cee7
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions ext_modules/_maix_nn/src/py_maix_nn_Model.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "stdlib.h"
#include <sys/time.h>

#define debug_line //printf("%s:%d %s %s %s \r\n", __FILE__, __LINE__, __FUNCTION__, __DATE__, __TIME__)

PyDoc_STRVAR(Maix_NN_Model_Object_type_doc, "neural network model object.\n");

Expand Down Expand Up @@ -786,8 +787,10 @@ static PyObject* Model_forward(ModelObject *self, PyObject *args, PyObject *kw_a
PyObject* result = Py_None;
PyObject* o_result_numpy2 = Py_None;


result = PyList_New(0);
if(self->outputs_len > 1)
{
result = PyList_New(0);
}
for(int i=0; i < self->outputs_len; ++i)
{
if(strcmp(output_fmt , "numpy") == 0) // -->numpy
Expand All @@ -805,7 +808,6 @@ static PyObject* Model_forward(ModelObject *self, PyObject *args, PyObject *kw_a
Py_DECREF(call_keywords);
Py_DECREF(call_args);
Py_DECREF(result_bytes);

if(outputs_layout == LIBMAIX_NN_LAYOUT_CHW)
{
// printf("py output layout is CHW\n");
Expand All @@ -823,8 +825,6 @@ static PyObject* Model_forward(ModelObject *self, PyObject *args, PyObject *kw_a
result = o_result_numpy2;
break;
}


PyList_Append(result, o_result_numpy2);
Py_DECREF(o_result_numpy2);
}
Expand All @@ -842,15 +842,7 @@ static PyObject* Model_forward(ModelObject *self, PyObject *args, PyObject *kw_a
Py_DECREF(o_input_bytes);

// return result;
if( self->outputs_len > 1)
{
return result;
}
else
{
return PyList_GetItem(result,0);
}

return result;

err1:
if(out_fmap)
Expand Down

0 comments on commit 1a0cee7

Please sign in to comment.