[14/38] trace-cmd: Simplify msg_free() by using min sizes
diff mbox series

Message ID 20180103175336.845166833@goodmis.org
State New, archived
Headers show
Series
  • trace-cmd: Simplify the msg handling
Related show

Commit Message

Steven Rostedt Jan. 3, 2018, 5:52 p.m. UTC
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

msg_free() only needs to free the extra data pointer if the min_size for the
command is something greater than zero.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 trace-msg.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Patch
diff mbox series

diff --git a/trace-msg.c b/trace-msg.c
index 943eaa5bf15c..406f44105470 100644
--- a/trace-msg.c
+++ b/trace-msg.c
@@ -249,17 +249,11 @@  static int tracecmd_msg_create(u32 cmd, struct tracecmd_msg *msg)
 
 static void msg_free(struct tracecmd_msg *msg)
 {
-	switch (ntohl(msg->hdr.cmd)) {
-	case MSG_TINIT:
-		free(msg->opt);
-		break;
-	case MSG_RINIT:
-		free(msg->port_array);
-		break;
-	case MSG_SENDMETA:
+	int cmd = ntohl(msg->hdr.cmd);
+
+	/* If a min size is defined, then the buf needs to be freed */
+	if (cmd < MSG_FINMETA && (msg_min_sizes[cmd] > 0))
 		free(msg->buf);
-		break;
-	}
 }
 
 static int tracecmd_msg_send(int fd, struct tracecmd_msg *msg)