From f51d58bd2e386ca84550bd234ff22c1292d12e09 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 5 Aug 2025 19:07:47 +0200 Subject: [PATCH] MINOR: pools: force the name at creation time to be a const. This is already the case as all names are constant so that's fine. If it would ever change, it's not very hard to just replace it in-situ via an strdup() and set a flag to mention that it's dynamically allocated. We just don't need this right now. One immediately visible effect is in "show pools detailed" where the names are no longer truncated. --- include/haproxy/pool-t.h | 2 +- include/haproxy/pool.h | 4 ++-- src/pool.c | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h index 524c871b8..4a8752ad6 100644 --- a/include/haproxy/pool-t.h +++ b/include/haproxy/pool-t.h @@ -70,7 +70,7 @@ struct pool_cache_head { */ struct pool_registration { struct list list; /* link element */ - char name[12]; /* name of the pool */ + const char *name; /* name of the pool */ unsigned int size; /* expected object size */ unsigned int flags; /* MEM_F_* */ unsigned int align; /* expected alignment; 0=unspecified */ diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index 963e5b6ae..3c9651e40 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -123,8 +123,8 @@ unsigned long long pool_total_allocated(void); unsigned long long pool_total_used(void); void pool_flush(struct pool_head *pool); void pool_gc(struct pool_head *pool_ctx); -struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags); -struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg); +struct pool_head *create_pool(const char *name, unsigned int size, unsigned int flags); +struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg); void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size); void *pool_destroy(struct pool_head *pool); void pool_destroy_all(void); diff --git a/src/pool.c b/src/pool.c index 43359403f..507a52032 100644 --- a/src/pool.c +++ b/src/pool.c @@ -290,8 +290,9 @@ static int mem_should_fail(const struct pool_head *pool) * is available for a new creation. Two flags are supported : * - MEM_F_SHARED to indicate that the pool may be shared with other users * - MEM_F_EXACT to indicate that the size must not be rounded up + * The name must be a stable pointer during all the program's life time. */ -struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) +struct pool_head *create_pool(const char *name, unsigned int size, unsigned int flags) { struct pool_registration *reg; struct pool_head *pool; @@ -300,7 +301,7 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) if (!reg) return NULL; - strlcpy2(reg->name, name, sizeof(reg->name)); + reg->name = name; reg->size = size; reg->flags = flags; reg->align = 0; @@ -314,7 +315,7 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) /* create a pool from a pool registration. All configuration is taken from * there. */ -struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg) +struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg) { unsigned int extra_mark, extra_caller, extra; unsigned int flags = reg->flags;