Fix off-by-one and double list size instead of steady increment
authorDavid Goulet <dgoulet@efficios.com>
Fri, 20 Jan 2012 20:07:15 +0000 (15:07 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 20 Jan 2012 20:07:15 +0000 (15:07 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/kernel.h

index a8fd844d961d06dc41a2dae3450839039fa157a6..6264521dee126d7585d1cb721f9ee13227d12457 100644 (file)
@@ -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");
index 2fbaca91ef112d75a5e5289d3dbed2bc223adf80..c4c687e5b97eade8b1b0ad6e6bcd97cd6cb7a770 100644 (file)
@@ -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);
This page took 0.040114 seconds and 4 git commands to generate.