[ldns-users] contrib/python: memory leak in ldns_pkt.new_query
Karel Slany
karel.slany at nic.cz
Wed Aug 7 09:26:00 UTC 2013
Hello Johannes,
I'll have look at it.
K.
Am 06.08.2013 19:59, schrieb Johannes Naab:
> Hi,
>
> The python wrapper for ldns appears to leak memory when packets are
> created by ldns_pkt.new_query.
>
> The following is a short example (tested in ldns-1.6.16, Python 2.7.5
> Linux 3.10, amd64):
> #!/usr/bin/env python2.7
> import ldns
>
> dname = ldns.ldns_dname("test.nic.cz")
>
> def leak():
> pkt = ldns.ldns_pkt.new_query(dname, ldns.LDNS_RR_TYPE_A,
> ldns.LDNS_RR_CLASS_IN, 0)
>
> while True:
> leak()
>
>
> Root of the problem seems to be, that the pointer to the ldns_pkt struct
> is not considered owned by the swig wrapper, and thus the pkt struct is
> not freed upon garbage collection in python.
>
> import ldns
> dname = ldns.ldns_dname("test.nic.cz")
> pkt = ldns.ldns_pkt.new_query(dname, ldns.LDNS_RR_TYPE_A,
> ldns.LDNS_RR_CLASS_IN, 0)
> print pkt.thisown
>
> => False.
>
> If new_query is replaced by new_query_frm_str the packet is "owned" by
> the swig wrapper, and the packet does not leak.
>
>
> pkt = ldns.ldns_pkt.new_query_frm_str(str(dname), ldns.LDNS_RR_TYPE_A,
> ldns.LDNS_RR_CLASS_IN, 0)
> print pkt.thisown
>
> => True
>
> I tried to convince swig that the struct should be owned by the wrapper
> by inserting a "%newobject ldns_pkt_query_new;" below line 44 in
> contrib/python/ldns_packet.i. This made swig own the pointer, but
> freeing the packet on garbage collection made python crash (memory
> corruption, double free). My knowledge and understanding of swig is limited.
>
>
> Johannes
> _______________________________________________
> ldns-users mailing list
> ldns-users at open.nlnetlabs.nl
> http://open.nlnetlabs.nl/mailman/listinfo/ldns-users
>
More information about the ldns-users
mailing list