[Bf-committers] Mem leak?

Kenneth Styrberg kenneth.styrberg at bredband.net
Wed Feb 27 19:50:18 CET 2008


Hi, I saw a commit to fix mem leaks in cloth.

trunk/blender/source/blender/blenkernel/intern/cloth.c

But there is a leak lurking in this code. If "bvh->current_xold" is NULL the code will never free "bvh->current_x".
Solution is to move "bvh->current_xold = MEM_callocN ( sizeof ( MVert ) * bvh->numverts, "bvh->current_xold" );" 
until after NULL check of "bvh->current_x".


    bvh->current_x = MEM_callocN ( sizeof ( MVert ) * bvh->numverts, 
"bvh->current_x" );
    bvh->current_xold = MEM_callocN ( sizeof ( MVert ) * bvh->numverts, 
"bvh->current_xold" );
    
    if (bvh->current_x == NULL)
    {
        printf("bvh: Out of memory.\n");
        MEM_freeN(bvh);
        return NULL;
    }
    
    if (bvh->current_xold == NULL)
    {
        printf("bvh: Out of memory.\n");
        MEM_freeN(bvh);
        return NULL;                        <---------------- HERE 
"bvh->current_x" is NOT NULL!
    }

   


More information about the Bf-committers mailing list