memory leak

john g john.pythonlist at gmail.com
Wed Jan 24 20:06:56 EST 2007


i have a memory leak issue with extension function that im working on. it
reads data from a binary file into a stl vector then creates a new list to
pass back to the python interface. the function works the first 1021 times
but then gives a segmentation fault (core dumped). heres the business part
of the code:


//read data
    vector<float> data;
    float temp;


    for(int x=0;x<np*2;x++)
    {
        fread(&temp,sizeof(float),1,datfil);
        data.push_back(temp);
    }


    //convert vector to list
    PyObject *newlist = PyList_New(np*2);
    PyList_SetItem(newlist, 0,PyFloat_FromDouble(data[0]));
    for(int x=0;x<np*2;x++)
    {
        PyList_SetItem(newlist, x,PyFloat_FromDouble(data[x]));
    }






    //send back list
    return newlist;

thanks for any advice
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070124/26f61367/attachment.html>


More information about the Python-list mailing list