Help with memory leak (malloc)

Posted by user146780 on Stack Overflow See other posts from Stack Overflow or by user146780
Published on 2010-05-24T21:42:33Z Indexed on 2010/05/24 21:51 UTC
Read the original article Hit count: 151

Filed under:
|
|

I'v followed a tutorial to use OGL tesselaton. In one of the callbacks there is a malloc and it creates a leak every time I render a new frame.

void CALLBACK combineCallback(GLdouble coords[3], GLdouble *vertex_data[4],
                              GLfloat weight[4], GLdouble **dataOut)
{
    GLdouble *vertex;

    vertex = (GLdouble *) malloc(6 * sizeof(GLdouble));
    vertex[0] = coords[0];
    vertex[1] = coords[1];
    vertex[2] = coords[2];


    for (int i = 3; i < 6; i++)
    {

        vertex[i] = weight[0] * vertex_data[0][i] +
            weight[1] * vertex_data[0][i] +
            weight[2] * vertex_data[0][i] +
            weight[3] * vertex_data[0][i];
    }


    *dataOut = vertex;


}

I'v tried to free(vertex) but then the polygons did not render. I also tried allocating on the heap then doing delete(vertex) but then the polygon rendered awkwardly. I'm not sure what to do.

Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about c