Discussions on GFL SDK, the graphic library for reading and writing graphic files
Moderators: XnTriq , helmut , xnview
Ithier
Posts: 47 Joined: Fri Nov 19, 2004 10:50 am
Location: Paris, France
Post
by Ithier » Mon Nov 30, 2009 10:48 am
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
xnview
Author of XnView
Posts: 42539 Joined: Mon Oct 13, 2003 7:31 am
Location: France
Post
by xnview » Mon Nov 30, 2009 11:00 am
You must check the returns value of gflGetFileInformationFromMemory
Pierre.
Ithier
Posts: 47 Joined: Fri Nov 19, 2004 10:50 am
Location: Paris, France
Post
by Ithier » Mon Nov 30, 2009 11:14 am
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
xnview
Author of XnView
Posts: 42539 Joined: Mon Oct 13, 2003 7:31 am
Location: France
Post
by xnview » Mon Nov 30, 2009 11:32 am
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.
dominique
Posts: 72 Joined: Thu Nov 08, 2007 9:22 am
Post
by dominique » Thu Dec 03, 2009 1:49 pm
What happen if the gflLoadBitmap() don't succeed? Does the file info structure shouldn't be freed, is it?
Thanks
Dom
xnview
Author of XnView
Posts: 42539 Joined: Mon Oct 13, 2003 7:31 am
Location: France
Post
by xnview » Thu Dec 03, 2009 5:49 pm
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.
Grincheux
Posts: 33 Joined: Thu Nov 30, 2006 8:01 am
Location: Arbois - 39
Post
by Grincheux » Sat Dec 19, 2009 5:49 am
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.
xnview
Author of XnView
Posts: 42539 Joined: Mon Oct 13, 2003 7:31 am
Location: France
Post
by xnview » Mon Dec 21, 2009 3:58 pm
You don't use 'free' functions if there is an error?
Pierre.