pool.c: name becomes char array instead of pointer
This commit is contained in:
@@ -19,13 +19,15 @@
|
|||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
|
||||||
|
#define POOL_NAME_LENGTH (16) /* max name length including trailing \0 */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct list_head list_blocks; /* list of allocated blocks in pool */
|
struct list_head list_blocks; /* list of allocated blocks in pool */
|
||||||
char data[]; /* objects block */
|
char data[]; /* objects block */
|
||||||
} block_t;
|
} block_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name; /* pool name */
|
char name[POOL_NAME_LENGTH]; /* pool name */
|
||||||
u32 available; /* current available elements */
|
u32 available; /* current available elements */
|
||||||
u32 allocated; /* total objects allocated */
|
u32 allocated; /* total objects allocated */
|
||||||
u32 growsize; /* number of objects per block allocated */
|
u32 growsize; /* number of objects per block allocated */
|
||||||
|
@@ -50,7 +50,8 @@ pool_t *pool_create(const char *name, u32 growsize, size_t eltsize)
|
|||||||
if (eltsize < sizeof (struct list_head))
|
if (eltsize < sizeof (struct list_head))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((pool = malloc(sizeof (*pool)))) {
|
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->growsize = growsize;
|
||||||
pool->eltsize = eltsize;
|
pool->eltsize = eltsize;
|
||||||
pool->available = 0;
|
pool->available = 0;
|
||||||
@@ -156,7 +157,6 @@ void pool_destroy(pool_t *pool)
|
|||||||
# ifdef DEBUG_POOL
|
# ifdef DEBUG_POOL
|
||||||
log(5, "\n");
|
log(5, "\n");
|
||||||
# endif
|
# endif
|
||||||
free(pool->name);
|
|
||||||
free(pool);
|
free(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user