Closing pefile file handle

152 views
Skip to first unread message

Alex_H

unread,
May 10, 2011, 1:49:20 PM5/10/11
to pefile
I'm recursively scanning a directory and opening each file with
pefile. I'm a little worried about memory issues. Does anyone have any
recommendations for closing out the handle that pefile would have to
the file?

import pefile
p = pefile.PE("bad.exe")
p.close() <- Does anything exist like this?

I was thinking that I could pass the file name to a function and have
pefile open the file inside the function. Python's memory management
would deallocate the memory once the function returns. Any thoughts?
Would the function method work?

Thanks,

Alex

Ero Carrera

unread,
May 15, 2011, 5:19:37 PM5/15/11
to pef...@googlegroups.com

Hi,

If you do not keep references to the pefile.PE() instances the descriptor should be closed once the instance is freed by the garbage collector.

If you want to play it safe you could open the file yourself, read all the data, close the file and create an instance with the alternative form:

pe = pefile.PE(data=data_you_just_read)

Hope that helps,
--
Ero Carrera

> --
> You received this message because you are subscribed to the Google Groups "pefile" group.
> To post to this group, send email to pef...@googlegroups.com.
> To unsubscribe from this group, send email to pefile+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pefile?hl=en.
>

Alex_H

unread,
May 30, 2011, 9:23:26 PM5/30/11
to pefile
Cool. Thanks Ero, that's exactly what I needed. Once again thank you
for the help.
Reply all
Reply to author
Forward
0 new messages