All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Babeux <christian.babeux@efficios.com>
To: dgoulet@efficios.com
Cc: lttng-dev@lists.lttng.org
Subject: [PATCH lttng-tools] Fix: Memory leaks when calling get_cmdline_by_pid
Date: Thu, 28 Feb 2013 15:48:28 -0500	[thread overview]
Message-ID: <1362084510-10072-5-git-send-email-christian.babeux__7696.9133028344$1362084594$gmane$org@efficios.com> (raw)
In-Reply-To: <1362084510-10072-1-git-send-email-christian.babeux@efficios.com>

Callers of get_cmdline_by_pid must free(3) the returned string.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
---
 src/bin/lttng/commands/list.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c
index 8fec91f..5429df4 100644
--- a/src/bin/lttng/commands/list.c
+++ b/src/bin/lttng/commands/list.c
@@ -294,6 +294,7 @@ static int list_ust_events(void)
 	struct lttng_handle *handle;
 	struct lttng_event *event_list;
 	pid_t cur_pid = 0;
+	char *cmdline = NULL;
 
 	memset(&domain, 0, sizeof(domain));
 
@@ -322,7 +323,9 @@ static int list_ust_events(void)
 	for (i = 0; i < size; i++) {
 		if (cur_pid != event_list[i].pid) {
 			cur_pid = event_list[i].pid;
-			MSG("\nPID: %d - Name: %s", cur_pid, get_cmdline_by_pid(cur_pid));
+			cmdline = get_cmdline_by_pid(cur_pid);
+			MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
+			free(cmdline);
 		}
 		print_events(&event_list[i]);
 	}
@@ -349,6 +352,8 @@ static int list_ust_event_fields(void)
 	struct lttng_handle *handle;
 	struct lttng_event_field *event_field_list;
 	pid_t cur_pid = 0;
+	char *cmdline = NULL;
+
 	struct lttng_event cur_event;
 
 	memset(&domain, 0, sizeof(domain));
@@ -379,7 +384,9 @@ static int list_ust_event_fields(void)
 	for (i = 0; i < size; i++) {
 		if (cur_pid != event_field_list[i].event.pid) {
 			cur_pid = event_field_list[i].event.pid;
-			MSG("\nPID: %d - Name: %s", cur_pid, get_cmdline_by_pid(cur_pid));
+			cmdline = get_cmdline_by_pid(cur_pid);
+			MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
+			free(cmdline);
 		}
 		if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
 			print_events(&event_field_list[i].event);
-- 
1.8.1.3

  parent reply	other threads:[~2013-02-28 20:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1362084510-10072-1-git-send-email-christian.babeux@efficios.com>
2013-02-28 20:48 ` [PATCH lttng-tools] Fix: Memory leaks on error paths in config_read_session_name Christian Babeux
2013-02-28 20:48 ` [PATCH lttng-tools] Fix: Memory leaks on error paths when exporting consumerd libdir in env Christian Babeux
2013-02-28 20:48 ` [PATCH lttng-tools] Fix: Memory leaks on unknown hashtable type error handling Christian Babeux
2013-02-28 20:48 ` Christian Babeux [this message]
2013-02-28 20:48 ` [PATCH lttng-tools] Fix: Memory leak when zmalloc fail on kernel channel allocation Christian Babeux
2013-02-28 20:48 ` [PATCH lttng-tools] Fix: Use after free on spawn_sessiond error path in check_sessiond Christian Babeux
2013-03-21 17:32 ` [PATCH lttng-tools] Fix: Memory leak on error paths of relay_add_stream David Goulet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1362084510-10072-5-git-send-email-christian.babeux__7696.9133028344$1362084594$gmane$org@efficios.com' \
    --to=christian.babeux@efficios.com \
    --cc=dgoulet@efficios.com \
    --cc=lttng-dev@lists.lttng.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.