From 9a9e46b03dd7dc0a5162b52804c8323b0ee779df Mon Sep 17 00:00:00 2001 From: Tommi Rantanen Date: Mon, 4 Sep 2023 16:36:12 +0300 Subject: [PATCH] lib: rest_client: Fix memory leak during timeout This issue was pointed out by Coverity. Signed-off-by: Tommi Rantanen --- subsys/net/lib/rest_client/src/rest_client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/rest_client/src/rest_client.c b/subsys/net/lib/rest_client/src/rest_client.c index d840273a3b28..8a26a6402915 100644 --- a/subsys/net/lib/rest_client/src/rest_client.c +++ b/subsys/net/lib/rest_client/src/rest_client.c @@ -197,7 +197,8 @@ static int rest_client_sckt_connect(int *const fd, /* Check if timeout has already elapsed */ if (time_used >= *timeout_ms) { LOG_WRN("Timeout occurred during DNS query"); - return -ETIMEDOUT; + ret = -ETIMEDOUT; + goto clean_up; } } @@ -244,7 +245,8 @@ static int rest_client_sckt_connect(int *const fd, /* Check if timeout has already elapsed */ if (time_used >= *timeout_ms) { LOG_WRN("Timeout occurred during socket connect"); - return -ETIMEDOUT; + ret = -ETIMEDOUT; + goto clean_up; } *timeout_ms -= time_used; }