<div dir="ltr">I think I found the problem. At line 1137 in resolver.c, ldns_pkt_free() is unconditionally called on answer_pkt, but if ldns_wire2pkt() failed answer_pkt is not pointing at allocated memory. Changing it so that ldns_pkt_free() is only called if stat is LDNS_STATUS_OK seems to fix the problem. At least my code doesn't segfault any more if I do that.<div>
<br></div><div>/Calle</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 13 June 2014 11:07, Calle Dybedahl <span dir="ltr"><<a href="mailto:calle@init.se" target="_blank">calle@init.se</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello.<div><br></div><div>Here's some C code that, at least right now, makes ldns segfault when trying to free memory that was never allocated. The server in question does send back data that is in some way malformed, so in some way I guess ldns is insufficiently paranoid.</div>

<div><br></div><div>I'm trying to look into the problem, but since I'm neither a very good C programmer nor very familiar with the ldns internals I'm not proceeding very quickly. So I'm hoping someone else will go "Oh, right, that's the problem" and fix it right away :-)</div>
<span class="HOEnZb"><font color="#888888">
<div><br></div><div>/Calle</div><div><br></div><div><br></div></font></span></div>
</blockquote></div><br></div>