Crash when calling gflFreeFileInformation

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

Post Reply
User avatar
Ithier
Posts: 47
Joined: Fri Nov 19, 2004 10:50 am
Location: Paris, France
Contact:

Crash when calling gflFreeFileInformation

Post 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
User avatar
xnview
Author of XnView
Posts: 43444
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Crash when calling gflFreeFileInformation

Post by xnview »

You must check the returns value of gflGetFileInformationFromMemory
Pierre.
User avatar
Ithier
Posts: 47
Joined: Fri Nov 19, 2004 10:50 am
Location: Paris, France
Contact:

Re: Crash when calling gflFreeFileInformation

Post 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
User avatar
xnview
Author of XnView
Posts: 43444
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Crash when calling gflFreeFileInformation

Post 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 :-)
Pierre.
User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Re: Crash when calling gflFreeFileInformation

Post by dominique »

What happen if the gflLoadBitmap() don't succeed? Does the file info structure shouldn't be freed, is it?
Thanks
Dom
User avatar
xnview
Author of XnView
Posts: 43444
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Crash when calling gflFreeFileInformation

Post 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
Pierre.
User avatar
Grincheux
Posts: 33
Joined: Thu Nov 30, 2006 8:01 am
Location: Arbois - 39
Contact:

Re: Crash when calling gflFreeFileInformation

Post 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
Kenavo.
User avatar
xnview
Author of XnView
Posts: 43444
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Crash when calling gflFreeFileInformation

Post by xnview »

You don't use 'free' functions if there is an error?
Pierre.
Post Reply