]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ngtcp2: use custom mem funcs
authorDavid Zhuang <dzhuang@roblox.com>
Wed, 6 Aug 2025 00:45:06 +0000 (17:45 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 18 Aug 2025 11:25:52 +0000 (13:25 +0200)
Pass curl's memory functions to the nghttp3 and ngtcp2 functions that
allow them. This allows custom memory functions passed by the curl user
to be used in nghttp3 and ngtcp2.

Closes #18196

lib/vquic/curl_ngtcp2.c
lib/vquic/curl_osslq.c
lib/vquic/vquic.c
lib/vquic/vquic_int.h

index 64670251375074af3974859855fec57ff376fb03..575ebb9022e09c00795bbf4dcc0a10d5dfc9c60d 100644 (file)
@@ -1212,7 +1212,7 @@ static CURLcode init_ngh3_conn(struct Curl_cfilter *cf,
   rc = nghttp3_conn_client_new(&ctx->h3conn,
                                &ngh3_callbacks,
                                &ctx->h3settings,
-                               nghttp3_mem_default(),
+                               Curl_nghttp3_mem(),
                                cf);
   if(rc) {
     failf(data, "error creating nghttp3 connection instance");
@@ -2475,7 +2475,7 @@ static const struct alpn_spec ALPN_SPEC_H3 = {
                               &ctx->connected_path,
                               NGTCP2_PROTO_VER_V1, &ng_callbacks,
                               &ctx->settings, &ctx->transport_params,
-                              NULL, cf);
+                              Curl_ngtcp2_mem(), cf);
   if(rc)
     return CURLE_QUIC_CONNECT_ERROR;
 
index fa2c0a2899e88bb93677afc7941a1858cbc0c2af..3dd9753a729c28ff654264103c22df7f038e71a0 100644 (file)
@@ -1106,7 +1106,7 @@ static CURLcode cf_osslq_h3conn_init(struct cf_osslq_ctx *ctx, SSL *conn,
   rc = nghttp3_conn_client_new(&h3->conn,
                                &ngh3_callbacks,
                                &h3->settings,
-                               nghttp3_mem_default(),
+                               Curl_nghttp3_mem(),
                                user_data);
   if(rc) {
     result = CURLE_OUT_OF_MEMORY;
index f8ce34129baf48c8d188ce5b42b9c1af8287f9a9..43a2c950216b43a78b5ab69969231c6d794af2d9 100644 (file)
@@ -724,6 +724,62 @@ CURLcode Curl_conn_may_http3(struct Curl_easy *data,
   return CURLE_OK;
 }
 
+#if defined(USE_NGTCP2) || defined(USE_NGHTTP3)
+
+static void *Curl_ngtcp2_malloc(size_t size, void *user_data)
+{
+  (void)user_data;
+  return Curl_cmalloc(size);
+}
+
+static void Curl_ngtcp2_free(void *ptr, void *user_data)
+{
+  (void)user_data;
+  Curl_cfree(ptr);
+}
+
+static void *Curl_ngtcp2_calloc(size_t nmemb, size_t size, void *user_data)
+{
+  (void)user_data;
+  return Curl_ccalloc(nmemb, size);
+}
+
+static void *Curl_ngtcp2_realloc(void *ptr, size_t size, void *user_data)
+{
+  (void)user_data;
+  return Curl_crealloc(ptr, size);
+}
+
+#ifdef USE_NGTCP2
+static struct ngtcp2_mem curl_ngtcp2_mem = {
+  NULL,
+  Curl_ngtcp2_malloc,
+  Curl_ngtcp2_free,
+  Curl_ngtcp2_calloc,
+  Curl_ngtcp2_realloc
+};
+struct ngtcp2_mem *Curl_ngtcp2_mem(void)
+{
+  return &curl_ngtcp2_mem;
+}
+#endif
+
+#ifdef USE_NGHTTP3
+static struct nghttp3_mem curl_nghttp3_mem = {
+  NULL,
+  Curl_ngtcp2_malloc,
+  Curl_ngtcp2_free,
+  Curl_ngtcp2_calloc,
+  Curl_ngtcp2_realloc
+};
+struct nghttp3_mem *Curl_nghttp3_mem(void)
+{
+  return &curl_nghttp3_mem;
+}
+#endif
+
+#endif /* USE_NGTCP2 || USE_NGHTTP3 */
+
 #else /* CURL_DISABLE_HTTP || !USE_HTTP3 */
 
 CURLcode Curl_conn_may_http3(struct Curl_easy *data,
index d271368d2902d08bd1b1bcfd0cb7e8db91d9f92a..38189beb70385207be2475ef0b7463740e0aedbd 100644 (file)
@@ -91,4 +91,13 @@ CURLcode vquic_recv_packets(struct Curl_cfilter *cf,
 
 #endif /* !USE_HTTP3 */
 
+#ifdef USE_NGTCP2
+struct ngtcp2_mem;
+struct ngtcp2_mem *Curl_ngtcp2_mem(void);
+#endif
+#ifdef USE_NGHTTP3
+struct nghttp3_mem;
+struct nghttp3_mem *Curl_nghttp3_mem(void);
+#endif
+
 #endif /* HEADER_CURL_VQUIC_QUIC_INT_H */