]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
doh: fix memory leaks
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 2 Apr 2019 16:18:34 +0000 (18:18 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 11 Apr 2019 07:12:48 +0000 (09:12 +0200)
daemon/bindings/worker.c
modules/http/http_doh.lua

index e19f4bd0102d315c24e06e4e984853b982c9fca8..7f961406e30b4a4948c7728244837e33fface854 100644 (file)
@@ -14,6 +14,8 @@
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#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 */
 
index b9b1e757106165459cba421e629b004875353c66..8a061ee0ff1c0585c56307b3090bd7982d8e8187 100644 (file)
@@ -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