From 0e1c2fad3540fe3a17cbfa9cb3ac9d70670258f4 Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Fri, 26 May 2023 19:25:35 +0200 Subject: [PATCH] pex-msg: fix memory leak on fread fail in pex_msg_update_request_init Fix Coverty Scan CID 1521052 memory leak on fread fail in pex_msg_update_request_init. Signed-off-by: Christian Marangi --- pex-msg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pex-msg.c b/pex-msg.c index 1f00681..716fe0c 100644 --- a/pex-msg.c +++ b/pex-msg.c @@ -424,8 +424,10 @@ pex_msg_update_request_init(const uint8_t *pubkey, const uint8_t *priv_key, memcpy(&ctx->addr, addr, sizeof(ctx->addr)); memcpy(ctx->auth_key, auth_key, sizeof(ctx->auth_key)); memcpy(ctx->priv_key, priv_key, sizeof(ctx->priv_key)); - if (!fread(&ctx->req_id, sizeof(ctx->req_id), 1, pex_urandom)) + if (!fread(&ctx->req_id, sizeof(ctx->req_id), 1, pex_urandom)) { + free(ctx); return NULL; + } list_add_tail(&ctx->list, &requests); if (!gc_timer.pending) uloop_timeout_set(&gc_timer, 1000); -- 2.30.2