Page 1 of 1

Crash when calling gflFreeFileInformation

Posted: Mon Nov 30, 2009 10:48 am
by Ithier
Hi,

If gflGetFileInformationFromMemory returns an error (for example if I call it with a PNG image and I set the index parameter to jpeg) then when I call gflFreeFileInformation, the application crash.

Here is a code example that crash if you call it with a PNG image. Works fine with a jpeg image:

Code: Select all

#include "libgfl.h"
#include <fstream>
using namespace std;

int main(int argc, char* argv[])
{
	gflLibraryInit();

	//Read file in memory
	ifstream ficDoc (argv[1], ios::in|ios::binary|ios::ate);
	int data_size = ficDoc.tellg();
	GFL_UINT8* pData = new GFL_UINT8[data_size];
	ficDoc.seekg (0, ios::beg);
	ficDoc.read (reinterpret_cast<char*>(pData), data_size);
	ficDoc.close();

	GFL_FILE_INFORMATION    m_GflFI;
	gflGetFileInformationFromMemory(pData, data_size, gflGetFormatIndexByName("jpeg"), &m_GflFI);
	gflFreeFileInformation(&m_GflFI);

	return 0;
}
It is not very important as there is a workaround by not calling gflFreeFileInformation if gflGetFileInformationFromMemory returns an error.

Best regards.
Ithier

Re: Crash when calling gflFreeFileInformation

Posted: Mon Nov 30, 2009 11:00 am
by xnview
You must check the returns value of gflGetFileInformationFromMemory

Re: Crash when calling gflFreeFileInformation

Posted: Mon Nov 30, 2009 11:14 am
by Ithier
xnview wrote:You must check the returns value of gflGetFileInformationFromMemory
I know ! This is what I am doing it now.
But with an older GflSdk version (2.90) this was working fine.
I have encapsulated the GFL_FILE_INFORMATION in a class to not forget to free the structure, but now I cannot use it because of this regression.
As I said this not a very important problem as there is a workaround, but it is a little surprising to get a crash when you call gflFreeFileInformation.


Ithier

Re: Crash when calling gflFreeFileInformation

Posted: Mon Nov 30, 2009 11:32 am
by xnview
gflGetFileInformation fills the GFL_FILE_INFORMATION only if there is no error, so Free can only happens when there is no error. Perhaps you had no problem in previous version but it's not the way to use Free :-)

Re: Crash when calling gflFreeFileInformation

Posted: Thu Dec 03, 2009 1:49 pm
by dominique
What happen if the gflLoadBitmap() don't succeed? Does the file info structure shouldn't be freed, is it?
Thanks

Re: Crash when calling gflFreeFileInformation

Posted: Thu Dec 03, 2009 5:49 pm
by xnview
dominique wrote:What happen if the gflLoadBitmap() don't succeed? Does the file info structure shouldn't be freed, is it?
Thanks
The same, you must not free info struct

Re: Crash when calling gflFreeFileInformation

Posted: Sat Dec 19, 2009 5:49 am
by Grincheux
I have the same problem
All the returned values are checkecked and the function crashes...

Code: Select all

GFL_LoadImageFromFile			PROC	__lpszFileName:LPSTR
								LOCAL	_hBitmap:HBITMAP
								LOCAL	_Infos:GFL_FILE_INFORMATION
								LOCAL	_lpImage:LPIMAGE_INFOS

								mov		eax,__lpszFileName

								test	eax,eax
								jz		@Exit						; Le pointeur doit ĂȘtre valide ( <> NULL)

									lea		edx,_hBitmap
									lea		ecx,_Infos

									INVOKE	gflLoadBitmapIntoDDB,eax,edx,ADDR ImageParams,ecx

									and		eax,0000ffffh
									jnz		@Error

										INVOKE	GFL_GetBitsFromHandle,_hBitmap

										test	eax,eax
										jz		@Error

											mov		_lpImage,eax

											lea		edx,_Infos
											mov		eax,_lpImage

											movzx	ecx,Word Ptr (GFL_FILE_INFORMATION Ptr [edx]).Xdpi
											mov		(IMAGE_INFOS Ptr [eax]).dwXDpi,ecx

											movzx	ecx,Word Ptr (GFL_FILE_INFORMATION Ptr [edx]).Ydpi
											mov		(IMAGE_INFOS Ptr [eax]).dwYDpi,ecx

;											INVOKE	gflFreeFileInformation,ADDR _Infos

											mov		eax,_lpImage
											ret

@Error :

								xor		eax,eax

@Exit :

								ret
GFL_LoadImageFromFile			ENDP

Re: Crash when calling gflFreeFileInformation

Posted: Mon Dec 21, 2009 3:58 pm
by xnview
You don't use 'free' functions if there is an error?