From: Daniel Gustafsson Date: Mon, 13 May 2024 07:11:23 +0000 (+0200) Subject: websocket: Avoid memory leak in error path X-Git-Tag: curl-8_8_0~77 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=266baf2d345b5685678b433b8fcc9b427df7e419;p=thirdparty%2Fcurl.git websocket: Avoid memory leak in error path In the errorpath for randstr being too long to copy into the buffer we leak the randstr when returning CURLE_FAILED_INIT. Fix by using an explicit free on randstr in the errorpath. Closes: #13602 Reviewed-by: Daniel Stenberg --- diff --git a/lib/ws.c b/lib/ws.c index 86ed5ce17c..6ccf9e65fd 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -718,8 +718,10 @@ CURLcode Curl_ws_request(struct Curl_easy *data, REQTYPE *req) if(result) return result; DEBUGASSERT(randlen < sizeof(keyval)); - if(randlen >= sizeof(keyval)) + if(randlen >= sizeof(keyval)) { + free(randstr); return CURLE_FAILED_INIT; + } strcpy(keyval, randstr); free(randstr); for(i = 0; !result && (i < sizeof(heads)/sizeof(heads[0])); i++) {