From 78afe38a2062aa2843a65d9f27ec1f748d6cc91d Mon Sep 17 00:00:00 2001 From: Tomas Krizek Date: Mon, 8 Mar 2021 15:30:49 +0100 Subject: [PATCH] daemon/http: free allocated memory after sending error msg --- daemon/http.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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); } -- 2.47.2