From: x2018 Date: Mon, 10 Nov 2025 16:29:29 +0000 (+0800) Subject: cf-https-connect: allocate ctx at first in cf_hc_create() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0dacc0796960c9caf5c31e7cbde8c5c062797b3c;p=thirdparty%2Fcurl.git cf-https-connect: allocate ctx at first in cf_hc_create() Closes #19454 --- diff --git a/lib/cf-https-connect.c b/lib/cf-https-connect.c index 5d6724dbc5..085b93da64 100644 --- a/lib/cf-https-connect.c +++ b/lib/cf-https-connect.c @@ -587,20 +587,22 @@ static CURLcode cf_hc_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OK; size_t i; + ctx = calloc(1, sizeof(*ctx)); + if(!ctx) { + result = CURLE_OUT_OF_MEMORY; + goto out; + } + DEBUGASSERT(alpnids); DEBUGASSERT(alpn_count); DEBUGASSERT(alpn_count <= CURL_ARRAYSIZE(ctx->ballers)); if(!alpn_count || (alpn_count > CURL_ARRAYSIZE(ctx->ballers))) { failf(data, "https-connect filter create with unsupported %zu ALPN ids", alpn_count); - return CURLE_FAILED_INIT; - } - - ctx = calloc(1, sizeof(*ctx)); - if(!ctx) { - result = CURLE_OUT_OF_MEMORY; + result = CURLE_FAILED_INIT; goto out; } + for(i = 0; i < alpn_count; ++i) cf_hc_baller_assign(&ctx->ballers[i], alpnids[i], def_transport); for(; i < CURL_ARRAYSIZE(ctx->ballers); ++i)