From 90303eb8b5cce0cfe96cebae779bb68a64437c20 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Mon, 20 Dec 2021 15:10:17 +0100 Subject: [PATCH] pool.c: name becomes char array instead of pointer --- 2021/include/pool.h | 4 +++- 2021/libsrc/pool.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/2021/include/pool.h b/2021/include/pool.h index b2f7727..f64024e 100644 --- a/2021/include/pool.h +++ b/2021/include/pool.h @@ -19,13 +19,15 @@ #include "list.h" #include "bits.h" +#define POOL_NAME_LENGTH (16) /* max name length including trailing \0 */ + typedef struct { struct list_head list_blocks; /* list of allocated blocks in pool */ char data[]; /* objects block */ } block_t; typedef struct { - char *name; /* pool name */ + char name[POOL_NAME_LENGTH]; /* pool name */ u32 available; /* current available elements */ u32 allocated; /* total objects allocated */ u32 growsize; /* number of objects per block allocated */ diff --git a/2021/libsrc/pool.c b/2021/libsrc/pool.c index d1f2ddc..7383758 100644 --- a/2021/libsrc/pool.c +++ b/2021/libsrc/pool.c @@ -50,7 +50,8 @@ pool_t *pool_create(const char *name, u32 growsize, size_t eltsize) if (eltsize < sizeof (struct list_head)) return NULL; if ((pool = malloc(sizeof (*pool)))) { - pool->name = strdup(name); + strncpy(pool->name, name, POOL_NAME_LENGTH - 1); + pool->name[POOL_NAME_LENGTH - 1] = 0; pool->growsize = growsize; pool->eltsize = eltsize; pool->available = 0; @@ -156,7 +157,6 @@ void pool_destroy(pool_t *pool) # ifdef DEBUG_POOL log(5, "\n"); # endif - free(pool->name); free(pool); }