From: Petr Špaček Date: Tue, 2 Apr 2019 16:18:34 +0000 (+0200) Subject: doh: fix memory leaks X-Git-Tag: v4.0.0~10^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f1155b8acfa952b04dee09e2704fd86a1ccd4f4;p=thirdparty%2Fknot-resolver.git doh: fix memory leaks --- diff --git a/daemon/bindings/worker.c b/daemon/bindings/worker.c index e19f4bd01..7f961406e 100644 --- a/daemon/bindings/worker.c +++ b/daemon/bindings/worker.c @@ -14,6 +14,8 @@ along with this program. If not, see . */ +#include "contrib/cleanup.h" + #include "daemon/bindings/impl.h" #include "daemon/worker.h" @@ -60,11 +62,11 @@ static int wrk_resolve_pkt(lua_State *L) // FIXME: merge with wrk_resolve const struct kr_qflags options = {}; knot_pkt_t *pkt = *(knot_pkt_t **)lua_topointer(L, 1); - printf("%p\n", pkt); if (!pkt) lua_error_maybe(L, ENOMEM); - printf("%s\n", kr_pkt_text(pkt)); + auto_free char *debug = kr_pkt_text(pkt); + printf("%s\n", debug); /* Create task and start with a first question */ diff --git a/modules/http/http_doh.lua b/modules/http/http_doh.lua index b9b1e7571..8a061ee0f 100644 --- a/modules/http/http_doh.lua +++ b/modules/http/http_doh.lua @@ -70,7 +70,7 @@ local function serve_doh(h, stream) -- convert query to knot_pkt_t local wire = ffi.cast("void *", input) - local pkt = ffi.C.knot_pkt_new(wire, #input, nil); + local pkt = ffi.gc(ffi.C.knot_pkt_new(wire, #input, nil), ffi.C.knot_pkt_free) if not pkt then return 500, 'internal server error' end