From: David Goulet Date: Fri, 20 Jan 2012 20:07:15 +0000 (-0500) Subject: Fix off-by-one and double list size instead of steady increment X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=6725fe1993a3c70c5fddecf5a458f03b08852edd;hp=10a8a2237343699e3923d87e24dbf2d7fe225377 Fix off-by-one and double list size instead of steady increment Signed-off-by: Mathieu Desnoyers Signed-off-by: David Goulet --- 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);