kernel_list_events: fix file descriptor leak
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 10 Aug 2011 20:07:51 +0000 (16:07 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 11 Aug 2011 14:03:26 +0000 (10:03 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ltt-sessiond/kernel-ctl.c

index cfea8942da7f421d4eeaf272f59b51261fe08e3e..3879c2bbb3bc9c9bda33d47564ee5a9c0ccc0471 100644 (file)
@@ -587,7 +587,7 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
        fp = fdopen(fd, "r");
        if (fp == NULL) {
                perror("kernel tracepoint list fdopen");
-               goto error;
+               goto error_fp;
        }
 
        /*
@@ -606,7 +606,8 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
                        elist = realloc(elist, nbmem);
                        if (elist == NULL) {
                                perror("realloc list events");
-                               goto error;
+                               count = -ENOMEM;
+                               goto end;
                        }
                }
                strncpy(elist[count].name, event, LTTNG_SYMBOL_NAME_LEN);
@@ -615,11 +616,13 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
        }
 
        *events = elist;
-
        DBG("Kernel list events done (%zu events)", count);
-
+end:
+       fclose(fp);     /* closes both fp and fd */
        return count;
 
+error_fp:
+       close(fd);
 error:
        return -1;
 }
This page took 0.025484 seconds and 4 git commands to generate.