[ldns-users] pyldns - memory leaks and double freeing
Bedrich Kosata
bedrich.kosata at nic.cz
Fri Mar 25 08:48:33 UTC 2011
Hi everybody,
while trying to find a cause of a memory leak in a simple script, I
found a nest of memory related issues in the python bindings.
The problems are all related to one common problem - who takes care of
memory of composite objects, such as ldns_rr_lists or ldns_pkt.
For example, in the current version, ldns_pkt bindings use ldns_pkt_free
to free a packet structure, however, when a rr_list is taken from the
packet and returned from a function, the packet gets out of scope, is
freed and the rr_list refers to already freed memory.
On the other hand, a rr_list only frees its own memory, not memory of
the stored rrs. This can lead to memory leaks.
I am attaching two scripts that demonstrate these problems (it might be
necessary to have the sources patched with the "freeing None" patch I
sent last week).
I would be willing to have a stab at the problems (provided I get
clearance from my boss :)), but the only solution I think would be clean
enough, is to clone the necessary bits where needed. This might lead to
some inefficiency and slowdowns (probably not big), so I would like to
ask if this is ok.
If there is anyone else willing to fix this, I would be happy to act as
a tester.
Cheers
Beda
p.s.- test-pkt-free.py crashes with a segmentation fault,
test-rr-list.py ends up eating about 130 MB of memory and more than
400000 python objects which python cannot free.
--
Bedrich Kosata
CZ.NIC Labs <http://labs.nic.cz>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-pkt-free.py
Type: text/x-python
Size: 276 bytes
Desc: not available
URL: <http://lists.nlnetlabs.nl/pipermail/ldns-users/attachments/20110325/ef6798d6/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-rr-list.py
Type: text/x-python
Size: 467 bytes
Desc: not available
URL: <http://lists.nlnetlabs.nl/pipermail/ldns-users/attachments/20110325/ef6798d6/attachment-0001.py>
More information about the ldns-users
mailing list