From 6725fe1993a3c70c5fddecf5a458f03b08852edd Mon Sep 17 00:00:00 2001 From: David Goulet Date: Fri, 20 Jan 2012 15:07:15 -0500 Subject: [PATCH] Fix off-by-one and double list size instead of steady increment Signed-off-by: Mathieu Desnoyers Signed-off-by: David Goulet --- src/bin/lttng-sessiond/kernel.c | 10 +++++----- src/bin/lttng-sessiond/kernel.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index a8fd844d9..6264521de 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -574,15 +574,15 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events) * Init memory size counter * See kernel-ctl.h for explanation of this value */ - nbmem = KERNEL_EVENT_LIST_SIZE; + nbmem = KERNEL_EVENT_INIT_LIST_SIZE; elist = zmalloc(sizeof(struct lttng_event) * nbmem); while ((size = fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) { - if (count > nbmem) { + if (count >= nbmem) { DBG("Reallocating event list from %zu to %zu bytes", nbmem, - nbmem + KERNEL_EVENT_LIST_SIZE); - /* Adding the default size again */ - nbmem += KERNEL_EVENT_LIST_SIZE; + nbmem * 2); + /* Double the size */ + nbmem <<= 1; elist = realloc(elist, nbmem * sizeof(struct lttng_event)); if (elist == NULL) { perror("realloc list events"); diff --git a/src/bin/lttng-sessiond/kernel.h b/src/bin/lttng-sessiond/kernel.h index 2fbaca91e..c4c687e5b 100644 --- a/src/bin/lttng-sessiond/kernel.h +++ b/src/bin/lttng-sessiond/kernel.h @@ -29,7 +29,7 @@ * This is NOT an upper bound because if the real event list size is bigger, * dynamic reallocation is performed. */ -#define KERNEL_EVENT_LIST_SIZE 80 +#define KERNEL_EVENT_INIT_LIST_SIZE 64 int kernel_add_channel_context(struct ltt_kernel_channel *chan, struct lttng_kernel_context *ctx); -- 2.34.1