flat assembler
Message board for the users of flat assembler.

Index > IDE Development > FASMW.ASM - memory leak (?) Tomasz ?

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1080
Location: Belgium
ouadji 19 Jan 2011, 00:49

Tomasz, I think there is a small problem here (?)
Code:
FASMW.ASM

save_file_as:
      .....
       .....
       mov     eax,[ei.pszpath]
    or      eax,eax
     jnz     alloc_ok
    invoke  VirtualAlloc,0,0C000000h,MEM_COMMIT,PAGE_READWRITE   ;1000h
 mov     [ei.pszpath],eax
      alloc_ok:
     mov     [lparam],eax
        mov     [ofn.lpstrFile],eax
 mov     [ofn.lpstrFilter],asm_filter
        mov     [ofn.Flags],OFN_EXPLORER+OFN_HIDEREADONLY+OFN_OVERWRITEPROMPT
       invoke  GetSaveFileName,ofn
 or      eax,eax
     jz      save_cancelled
      mov     eax,[ei.pszpath]
    .....
       .....

save_cancelled:

        mov     eax,[lparam]
        xchg    eax,[ei.pszpath]
    cmp     eax,[ei.pszpath]
    je      finish
      invoke  VirtualFree,eax,0,MEM_RELEASE
       .....
       .....
    

GetSaveFileName ==> Cancel ==> eax=0
save_cancelled: ... save is not canceled !
[lparam] == [ei.pszpath] always ! ... then "je finish".

I checked it with my debugger and also with the Windows Task Manager ...
(with 200MB of memory allocation to be sure of the result )
results: "VirtualAlloc" is not canceled.
if I repeat the operation, "save as - cancel - save as - cancel ..."
my memory allocation rises to 400, 600, 800 MB ...


after "cancel" I think It would be nice to clear [ei.pszpath] too.
Probably not necessary but "aesthetically" more correct.

to solve this problem, maybe something like this (?)
Code:
  mov     eax,[ei.pszpath]
    or      eax,eax
     mov     [lparam],eax ;<--- here
  jnz     alloc_ok
    invoke  VirtualAlloc,0,1000h,MEM_COMMIT,PAGE_READWRITE 
     mov     [ei.pszpath],eax
alloc_ok:
;  mov     [lparam],eax
    



_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 19 Jan 2011, 00:49
View user's profile Send private message Send e-mail Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1080
Location: Belgium
ouadji 20 Jan 2011, 20:41
Code:
"0.95.05"

      save_cancelled:
     ;mov    eax,[lparam]
        ;xchg   eax,[ei.pszpath]
    ;cmp    eax,[ei.pszpath]
    ;je     finish
      ;invoke VirtualFree,eax,0,MEM_RELEASE
       invoke  SendMessage,[hwnd_tabctrl],TCM_GETCURSEL,0,0
        invoke  SendMessage,[hwnd_tabctrl],TCM_SETITEM,eax,ei
       jmp     finish
    
thank you Tomasz for this fix.

Your solution is another way of looking at things,
but I checked it, everything works correctly.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 20 Jan 2011, 20:41
View user's profile Send private message Send e-mail Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1080
Location: Belgium
ouadji 21 Jan 2011, 01:25
Code:
fmsave:
      mov     [ei.header.mask],TCIF_PARAM
 invoke  SendMessage,[hwnd_tabctrl],TCM_GETITEM,[wparam],ei
  or      eax,eax
     jz      failed
      mov     eax,[ei.pszpath] ;eax != 0, but *eax="" => CreateFile fail!
    or      eax,eax
     jz      failed
      invoke  CreateFile,eax,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
    
but with your solution, the path is empty,
*[ei.pszpath] == "" and CreateFile fail.
Yes ...it does not matter! (but this is not aesthetic)
I think my solution was better.


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 21 Jan 2011, 01:25
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 21 Jan 2011, 05:06
Yes, I now leave the memory block allocated but unused (until the next time). It may appear a bit "dirty"... But, on the other hand, if you then do "save" once again, the memory is already allocated -why allocate it two times?
Post 21 Jan 2011, 05:06
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1080
Location: Belgium
ouadji 21 Jan 2011, 09:37
Quote:

"It may appear a bit "dirty"..."
relax, just a little bit Wink Razz
Quote:

"why allocate it two times?"
yes, ok, good idea
but in this case, the string "path" is empty
and in "fmsave", this is not :
Code:
mov     eax,[ei.pszpath]
or      eax,eax
jz      failed ;-----> out
    
but
Code:
invoke   CreateFile
cmp       eax,-1
je    failed ;-----> here out
    

and that ... it's a bit "dirty".
sorry, I'm a perfectionist ... (only with code Wink )

then, maybe this ? (to be politically perfect Wink )
Code:
mov       eax,[ei.pszpath]
or  eax,eax
jz   failed
mov   ebx,[eax]       ;+
or        ebx,ebx         ;+ Memory allocated by VirtualAlloc 
jz      failed          ;+ is automatically initialized to zero
invoke       CreateFile
    

have a good day Tomasz, and thank you for your reply.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 21 Jan 2011, 09:37
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.