FreeImage_LoadFromMemory memory leak

hi, in a previous post i was trying to find a massive memory leak. now i’ve found that it happens to be in this function

ofImage  testApp::fJPEG( BYTE* jpegBytes )  
	memBuff= FreeImage_OpenMemory	(	jpegBytes,lSize	 )	;  
	img=FreeImage_LoadFromMemory	(	FIF_JPEG,memBuff, JPEG_FAST	 );	  
	return ofImg;  

searching in the freeimage help forums some people says maby is at older versions.
it is possible to update the freeimage version that of uses? couls this be the problem?
the freeimage library in of has two files, an .h (header) file and a .a file that appears to be binary. how do i get the .a file with the updated freeimage version?

hi –

I’m not sure that it’s possible to switch but you can always try. again, you might have much better luck with your questions on the freeImage forum.

what platform/compiler are you on?

if you are on windows / codeblocks see the MINGW readme in the freeImage download.

  • zach

ps: about the two problems mentioned elsewhere on a different thread –
upside down – this is because 0,0 is top left, you need to flip the FIBITMAP
broken / strip / angles - this is because freeimage data is **not** contiguous in memory and you are treating it as if it is. see ofImage for examples of how to make in contiguous.

im on mac osx 10.5 macbook pro intel based
ill look in ofImage examples to rotate the FIBITMAP
still looking in fi forims
thanks a lot for your help

the freeimage-docs gave me one hint (which was obvious before)

DLL_API void DLL_CALLCONV FreeImage_CloseMemory(FIMEMORY *stream);

Close and free a memory stream.
When the stream is managed by FreeImage, the memory file is destroyed.
Otherwise (wrapped buffer), it’s destruction is left to the application driving FreeImage.
You always need to call this function once you’re done with a memory stream (whatever the way you opened the stream), or you will have a memory leak.

but i am using FreeImage_CloseMemory(memBuff);
and still the leak

this is the last version of code, that works very well but still with the leak.

ofImage  testApp::fJPEG( BYTE* jpegBytes )  
	 ofImage ofImg;  
	FIMEMORY* memBuff;  
	FIBITMAP* img;  
	memBuff= FreeImage_OpenMemory	(	jpegBytes,lSize	 )	;  
	img=FreeImage_LoadFromMemory	(	FIF_JPEG,memBuff, JPEG_FAST	 );	  
	unsigned width = FreeImage_GetWidth(img);  
	unsigned height = FreeImage_GetHeight(img);  
	unsigned pitch = FreeImage_GetPitch(img)-1;//add 1 to pitch tho solve odd distortion  
	unsigned bpp=FreeImage_GetBPP(img);  
	FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(img);  
 // cout<< width<<"|"<<height<<"|"<<bpp<<"|"<<(int)pitch<<endl;  
	BYTE *bits = (BYTE*)malloc(height * pitch);  
// convert the bitmap to raw bits (top-left pixel first)  
	FreeImage_ConvertToRawBits(bits, img, pitch, bpp,FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK,FI_RGBA_BLUE_MASK, true);  
	return ofImg;  

most of the mods from original where made based on freeimage 3100 pdf

you malloc bits, but don’t free it up… that looks like a leak source – z

added free(bits); and solved the problem.
thanks z.