From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 04/13] gc: use fixed length buffer for storing consumer name Date: Thu, 4 Oct 2018 20:20:06 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: The length of a consumer name never exceeds 64 characters so no use to allocate a string. This is a mere code simplification. --- src/box/gc.c | 11 ++--------- src/box/gc.h | 4 +++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/box/gc.c b/src/box/gc.c index a45806b6..7de50e84 100644 --- a/src/box/gc.c +++ b/src/box/gc.c @@ -34,7 +34,7 @@ #include #include -#include +#include #define RB_COMPACT 1 #include @@ -82,13 +82,7 @@ gc_consumer_new(const char *name, const struct vclock *vclock, "malloc", "struct gc_consumer"); return NULL; } - consumer->name = strdup(name); - if (consumer->name == NULL) { - diag_set(OutOfMemory, strlen(name) + 1, - "malloc", "struct gc_consumer"); - free(consumer); - return NULL; - } + snprintf(consumer->name, GC_NAME_MAX, "%s", name); vclock_copy(&consumer->vclock, vclock); consumer->type = type; return consumer; @@ -98,7 +92,6 @@ gc_consumer_new(const char *name, const struct vclock *vclock, static void gc_consumer_delete(struct gc_consumer *consumer) { - free(consumer->name); TRASH(consumer); free(consumer); } diff --git a/src/box/gc.h b/src/box/gc.h index 2c03770d..fde4facf 100644 --- a/src/box/gc.h +++ b/src/box/gc.h @@ -42,6 +42,8 @@ extern "C" { struct gc_consumer; +enum { GC_NAME_MAX = 64 }; + /** Consumer type: WAL consumer, or SNAP */ enum gc_consumer_type { GC_CONSUMER_WAL = 1, @@ -59,7 +61,7 @@ struct gc_consumer { /** Link in gc_state::consumers. */ gc_node_t node; /** Human-readable name. */ - char *name; + char name[GC_NAME_MAX]; /** The vclock tracked by this consumer. */ struct vclock vclock; /** Consumer type, indicating that consumer only consumes -- 2.11.0