From 878fea902b1c509b61be1f18494edb1f647733b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 16 Jun 2021 15:08:21 -0400 Subject: [PATCH] Fix: rotation client example: leak of handle on error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1452927 Resource leak The system resource will not be reclaimed and reused, reducing the future availability of the resource. In setup_session: Leak of memory or pointers to system resources (CWE-404) CID 1452927 (#1 of 1): Resource leak (RESOURCE_LEAK)8. leaked_storage: Variable chan_handle going out of scope leaks the storage it points to Reported-by: Coverity Scan Signed-off-by: Jérémie Galarneau Change-Id: I4c215ac4a86f9f70fd5c9d3aa13f944d3d7a2cc7 --- doc/examples/rotation/rotate-client-example.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/examples/rotation/rotate-client-example.c b/doc/examples/rotation/rotate-client-example.c index ae641d895..5cb0887bf 100644 --- a/doc/examples/rotation/rotate-client-example.c +++ b/doc/examples/rotation/rotate-client-example.c @@ -53,7 +53,7 @@ static int setup_session(const char *session_name, const char *path) int ret; struct lttng_domain dom; struct lttng_event ev; - struct lttng_handle *chan_handle; + struct lttng_handle *chan_handle = NULL; printf("Creating session %s\n", session_name); ret = lttng_create_session(session_name, path); @@ -90,11 +90,10 @@ static int setup_session(const char *session_name, const char *path) goto end; } - lttng_destroy_handle(chan_handle); - ret = 0; end: + lttng_destroy_handle(chan_handle); return ret; } -- 2.34.1