From: Tomas Krizek Date: Mon, 8 Mar 2021 14:30:49 +0000 (+0100) Subject: daemon/http: free allocated memory after sending error msg X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ab1b0b83f9d98650d4ee847ec7fefe578783e0b;p=thirdparty%2Fknot-resolver.git daemon/http: free allocated memory after sending error msg --- diff --git a/daemon/http.c b/daemon/http.c index 313808706..d31280fce 100644 --- a/daemon/http.c +++ b/daemon/http.c @@ -216,6 +216,11 @@ static int send_err_status(struct http_ctx *ctx, int32_t stream_id) data->req = NULL; data->ttl = 0; prov.source.ptr = data; + + /* data will be freed in callback. */ + ret = nghttp2_session_set_stream_user_data(ctx->h2, stream_id, (void*)data); + if (ret != 0) + return kr_error(EIO); } ret = nghttp2_submit_response(ctx->h2, stream_id, hdrs_err, sizeof(hdrs_err)/sizeof(*hdrs_err), &prov); @@ -661,10 +666,11 @@ static int on_frame_recv_callback(nghttp2_session *h2, const nghttp2_frame *fram */ static void on_pkt_write(struct http_data *data, int status) { - if (!data || !data->req || !data->on_write) + if (!data) return; - data->on_write(data->req, status); + if (data->req && data->on_write) + data->on_write(data->req, status); free(data); }