Skip to content

Commit 537dfec

Browse files
committed
fixed memory free
1 parent 150af48 commit 537dfec

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

nvjpeg-python.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ static PyObject* NvJpeg_decode(NvJpeg* Self, PyObject* Argvs)
295295
unsigned char* data = NvJpegPythonImage2HostMemory(img);
296296
npy_intp dims[1] = {(npy_intp)((img->width)*(img->height))*3};
297297
PyObject* temp = PyArray_SimpleNewFromData(1, dims, NPY_UINT8, data);
298-
free(data);
298+
PyArray_ENABLEFLAGS((PyArrayObject*) temp, NPY_ARRAY_OWNDATA);
299+
// free(data);
299300

300301
PyObject* shape = Py_BuildValue("(i,i,i)", 3, img->height, img->width);
301302
NvJpegPython_destoryImage(&img);
@@ -310,7 +311,7 @@ static PyObject* NvJpeg_decode(NvJpeg* Self, PyObject* Argvs)
310311

311312
rtn = PyArray_SwapAxes((PyArrayObject*)temp, 0, 1);
312313
Py_DECREF(temp);
313-
314+
// Py_INCREF(rtn);
314315
return rtn;
315316
}
316317

@@ -338,11 +339,14 @@ static PyObject* NvJpeg_encode(NvJpeg* Self, PyObject* Argvs)
338339
}
339340

340341
NvJpegPythonHandle* m_handle = (NvJpegPythonHandle*)Self->m_handle;
341-
NvJpegPythonImage* img = NvJpegPython_createImageFromHost(PyArray_DIM(vecin, 0), PyArray_DIM(vecin, 1), (const unsigned char*)PyArray_BYTES(vecin), 3);
342+
NvJpegPythonImage* img = NvJpegPython_createImageFromHost(PyArray_DIM(vecin, 1), PyArray_DIM(vecin, 0), (const unsigned char*)PyArray_BYTES(vecin), 3);
342343
NvJpegJpegData* data = NvJpegPython_encode(m_handle, img, quality);
343344

344345
PyObject* rtn = PyByteArray_FromStringAndSize((const char*)data->data, data->size);
346+
347+
NvJpegPython_destoryJpegData(&data);
345348
NvJpegPython_destoryImage(&img);
349+
346350
return rtn;
347351
}
348352

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from distutils.core import setup, Extension
1111
setup(name='pynvjpeg',
12-
version='0.0.2',
12+
version='0.0.3',
1313
ext_modules=[Extension('nvjpeg', ['nvjpeg-python.c'])],
1414
author="Usingnet",
1515
author_email="developer@usingnet.com",

0 commit comments

Comments
 (0)