]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cf-https-connect: allocate ctx at first in cf_hc_create()
authorx2018 <xkernel.wang@foxmail.com>
Mon, 10 Nov 2025 16:29:29 +0000 (00:29 +0800)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 11 Nov 2025 15:18:55 +0000 (16:18 +0100)
Closes #19454

lib/cf-https-connect.c

index 5d6724dbc5e2861ef6b85d85bfe9509e3b5cadc4..085b93da64af898e5445072905b46aba734ea0c3 100644 (file)
@@ -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)