In a shared utility library called shrUtils.h there is a major memory leak in the function shrSavePPM4ub()
This function strips the four channel of the passed image data before calling savePPM(). To do this, it allocates a new buffer of size w * h * 3 bytes which is never freed.
////////////////////////////////////////////////////////////////////////////////
//! Save PPM image file (with unsigned char as data element type, padded to 4 byte)
//! @return shrTrue if reading the file succeeded, otherwise shrFALSE
//! @param file name of the image file
//! @param data handle to the data read
//! @param w width of the image
//! @param h height of the image
////////////////////////////////////////////////////////////////////////////////
shrBOOL shrSavePPM4ub( const char* file, unsigned char *data, unsigned int w, unsigned int h)
{
// strip 4th component
int size = w * h;
unsigned char *ndata = (unsigned char*) malloc( sizeof(unsigned char) * size*3);
unsigned char *ptr = ndata;
for(int i=0; i<size; i++) {
*ptr++ = *data++;
*ptr++ = *data++;
*ptr++ = *data++;
data++;
}
return savePPM(file, ndata, w, h, 3);
}
Sorry if this is a known issue, I couldn’t find anything on the forums about it. I suppose its not a popular method. It’s easily fixed by changing the return line:
Glad to hear I’m being helpful! I also just noticed another memory leak in the same library, not sure if its fixed yet in the most recent source but it still appears in OpenCL examples on the site.