You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After the close method of a pefile.PE instance has been called, the garbage collector can't destroy the object due to a lot of reference cycles. This obviously causes memory leaks in long-time running processes.
HOW TO REPRODUCE
Python version 2.7.17
pefile version: 2018.8.8
Launch an htop parallely to the below code and look for RAM usage increasing more and more
import pefile
while True:
pe = pefile.PE(<filepath>)
pe.close()
or simply run the below code:
import pefile
class Test(pefile.PE):
def __del__(self):
print("Destroyed")
pe = Test(<filepath>)
pe.close()
pe = None
...won't print at all.
WORKAROUND (ugly)
Create a wrapper around the PE class:
class MyPE(pefile.PE):
def close_recursive(obj, target):
if isinstance(obj, list):
for val in obj:
close_recursive(val, target)
elif isinstance(obj, object):
try:
dictobj = obj.__dict__
if target in dictobj:
setattr(obj, target, None)
for attr, val in dictobj.items():
close_recursive(val, target)
except:
pass
def close(self):
for attr, val in self.__dict__.items():
close_recursive(val, "pe")
super(MyPE, self).close()
The text was updated successfully, but these errors were encountered:
PROBLEM
After the
close
method of apefile.PE
instance has been called, the garbage collector can't destroy the object due to a lot of reference cycles. This obviously causes memory leaks in long-time running processes.HOW TO REPRODUCE
Python version 2.7.17
pefile version: 2018.8.8
Launch an
htop
parallely to the below code and look for RAM usage increasing more and moreor simply run the below code:
...won't print at all.
WORKAROUND (ugly)
Create a wrapper around the PE class:
The text was updated successfully, but these errors were encountered: