From: Mathieu Desnoyers Date: Wed, 10 Aug 2011 20:07:51 +0000 (-0400) Subject: kernel_list_events: fix file descriptor leak X-Git-Tag: v2.0-pre11~10 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=61b73b12f14baa1826072f2265aa107c41ce518f;p=lttng-tools.git kernel_list_events: fix file descriptor leak Signed-off-by: Mathieu Desnoyers --- diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index cfea8942d..3879c2bbb 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -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; }