Python C模块内存泄漏

时间:2017-07-04 03:32:16

标签: python c python-2.7 memory-leaks bitmap

我有一个适用于python的C库,它是项目rdpy(https://github.com/citronneur/rdpy)的一部分。 但是,有一个内存泄漏,我不能在python代码中删除:删除对象的引用(input = None,output = None),gc.collect()等。泄漏分析器,如pympler,也不显示对象占据记忆。我还发现在rdesktop项目中使用相同的代码(https://github.com/rdesktop/rdesktop/blob/master/bitmap.c),但它在那里正常工作,也许这是与python集成的问题。这个函数可以使内存泄漏吗?

/* Specific rename for RDPY integration */
#define uint8   unsigned char
#define uint16  unsigned short
#define unimpl(str, code)

#define  RD_BOOL    int
#define False   0
#define True    1
/* end specific rename */

......................................

static PyObject*
bitmap_decompress_wrapper(PyObject* self, PyObject* args)
{
    Py_buffer output, input;
    int width = 0, height = 0, bpp = 0;

    if (!PyArg_ParseTuple(args, "s*iis*i", &output, &width, &height, &input, &bpp))
        return NULL;

    if(bitmap_decompress((uint8*)output.buf, width, height, (uint8*)input.buf, input.len, bpp) == False)
        return NULL;

    Py_RETURN_NONE;
}

static PyMethodDef rle_methods[] =
{
     {"bitmap_decompress", bitmap_decompress_wrapper, METH_VARARGS, "decompress bitmap from microsoft rle algorithm."},
     {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
initrle(void)
{
     (void) Py_InitModule("rle", rle_methods);
}

0 个答案:

没有答案