From: Slavomir Kaslev <kaslevs@vmware.com>
To: linux-trace-devel@vger.kernel.org
Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com,
tstoyanov@vmware.com, ykaradzhov@vmware.com
Subject: [PATCH 5/8] trace-cmd: Fix a memory leak in tracecmd_msg_send_init_data
Date: Mon, 4 Feb 2019 09:08:52 +0200 [thread overview]
Message-ID: <20190204070855.8921-6-kaslevs@vmware.com> (raw)
In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com>
Fix tracecmd_msg_send_init_data leaking memory for the messages it receives.
Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
---
tracecmd/trace-msg.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
index f7ce863..b4b58d4 100644
--- a/tracecmd/trace-msg.c
+++ b/tracecmd/trace-msg.c
@@ -373,8 +373,7 @@ static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg *msg)
int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
unsigned int **client_ports)
{
- struct tracecmd_msg send_msg;
- struct tracecmd_msg recv_msg;
+ struct tracecmd_msg msg;
int fd = msg_handle->fd;
unsigned int *ports;
int i, cpus;
@@ -382,30 +381,41 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
*client_ports = NULL;
- tracecmd_msg_init(MSG_TINIT, &send_msg);
- ret = make_tinit(msg_handle, &send_msg);
+ tracecmd_msg_init(MSG_TINIT, &msg);
+ ret = make_tinit(msg_handle, &msg);
if (ret < 0)
- return ret;
+ goto out;
- ret = tracecmd_msg_send(fd, &send_msg);
+ ret = tracecmd_msg_send(fd, &msg);
if (ret < 0)
- return ret;
+ goto out;
+
+ msg_free(&msg);
- ret = tracecmd_msg_wait_for_msg(fd, &recv_msg);
+ ret = tracecmd_msg_wait_for_msg(fd, &msg);
if (ret < 0)
- return ret;
+ goto out;
- if (ntohl(recv_msg.hdr.cmd) != MSG_RINIT)
- return -EINVAL;
+ if (ntohl(msg.hdr.cmd) != MSG_RINIT) {
+ ret = -EINVAL;
+ goto error;
+ }
- cpus = ntohl(recv_msg.rinit.cpus);
+ cpus = ntohl(msg.rinit.cpus);
ports = malloc_or_die(sizeof(*ports) * cpus);
for (i = 0; i < cpus; i++)
- ports[i] = ntohl(recv_msg.port_array[i]);
+ ports[i] = ntohl(msg.port_array[i]);
*client_ports = ports;
+ msg_free(&msg);
return 0;
+
+error:
+ error_operation(&msg);
+out:
+ msg_free(&msg);
+ return ret;
}
static bool process_option(struct tracecmd_msg_handle *msg_handle,
--
2.19.1
next prev parent reply other threads:[~2019-02-04 7:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-04 7:08 [PATCH 0/8] trace-cmd protocol fixes Slavomir Kaslev
2019-02-04 7:08 ` [PATCH 1/8] trace-cmd: Remove unused global variable Slavomir Kaslev
2019-02-04 7:08 ` [PATCH 2/8] trace-cmd: Rename error_operation_for_server Slavomir Kaslev
2019-02-04 7:08 ` [PATCH 3/8] trace-cmd: Remove tracecmd_msg_handle/tracecmd_msg_server distinction Slavomir Kaslev
2019-02-04 7:08 ` [PATCH 4/8] trace-cmd: Check if connection is done when reading data in tracecmd_msg_read_data Slavomir Kaslev
2019-02-04 7:08 ` Slavomir Kaslev [this message]
2019-02-04 7:08 ` [PATCH 6/8] trace-cmd: Make tracecmd_msg_send_close return error code if any Slavomir Kaslev
2019-02-05 15:14 ` Steven Rostedt
2019-02-07 12:52 ` Slavomir Kaslev
2019-02-07 14:41 ` Steven Rostedt
2019-02-08 19:34 ` Steven Rostedt
2019-02-04 7:08 ` [PATCH 7/8] trace-cmd: Add tracecmd_msg_wait_close function Slavomir Kaslev
2019-02-04 7:08 ` [PATCH 8/8] trace-cmd: Acknowledge unexpected protocol messages Slavomir Kaslev
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=20190204070855.8921-6-kaslevs@vmware.com \
--to=kaslevs@vmware.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=slavomir.kaslev@gmail.com \
--cc=tstoyanov@vmware.com \
--cc=ykaradzhov@vmware.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).