Linux Trace Development
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Cc: Ross Zwisler <zwisler@google.com>
Subject: [PATCH] libtraceeval: Do not just copy vals for delta elements
Date: Tue, 10 Oct 2023 23:02:46 -0400	[thread overview]
Message-ID: <20231010230246.74894849@rorschach.local.home> (raw)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The traceeval_delta_start() on update just copied the values that were
passed in, but these elements are part of the internal traceeval. That
means on release, the strings will be freed. If the vals are simply
copied, then what was passed in is going to be freed.

Instead, do the same thing that is done on adding a new element, and call
traceeval_insert() to handle the update.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/delta.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/delta.c b/src/delta.c
index 544998dff412..9f308189fe1d 100644
--- a/src/delta.c
+++ b/src/delta.c
@@ -176,6 +176,22 @@ int traceeval_delta_query_size(struct traceeval *teval,
 				    nr_keys, results);
 }
 
+static int insert_vals(struct traceeval *teval, const struct traceeval_data *keys,
+		       const struct traceeval_data *vals, unsigned long long ts)
+{
+	struct traceeval_data new_vals[teval->nr_val_types] = {};
+	int nr_vals = teval->nr_val_types - 1;
+	int i;
+
+	for (i = 0; i < nr_vals; i++)
+		new_vals[i] = vals[i];
+
+	TRACEEVAL_SET_NUMBER_64(new_vals[i], ts);
+
+	return _teval_insert(teval, keys, teval->nr_key_types,
+			     new_vals, teval->nr_val_types);
+}
+
 static int delta_start(struct traceeval *teval,
 		       const struct traceeval_data *keys, size_t nr_keys,
 		       const struct traceeval_data *vals, size_t nr_vals,
@@ -183,7 +199,6 @@ static int delta_start(struct traceeval *teval,
 {
 	struct entry *entry;
 	int ret;
-	int i;
 
 	if (!teval->tdelta) {
 		teval_print_err(TEVAL_WARN, "traceeval_delta_start/continue: traceeval does not have delta");
@@ -208,27 +223,10 @@ static int delta_start(struct traceeval *teval,
 	if (ret < 0)
 		return ret;
 
-	if (ret) {
-		if (cont && TEVAL_TIMESTAMP(teval, entry->vals))
-			return 0;
-
-		for (i = 0; i < nr_vals; i++)
-			entry->vals[i] = vals[i];
-
-		TRACEEVAL_SET_NUMBER_64(entry->vals[i], timestamp);
-
+	if (ret && cont && TEVAL_TIMESTAMP(teval, entry->vals))
 		return 0;
-	} else {
-		struct traceeval_data new_vals[teval->nr_val_types] = {};
-
-		for (i = 0; i < nr_vals; i++)
-			new_vals[i] = vals[i];
 
-		TRACEEVAL_SET_NUMBER_64(new_vals[i], timestamp);
-
-		return _teval_insert(teval, keys, teval->nr_key_types,
-				     new_vals, teval->nr_val_types);
-	}
+	return insert_vals(teval, keys, vals, timestamp);
 }
 
 /*
-- 
2.42.0


                 reply	other threads:[~2023-10-11  3:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231010230246.74894849@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=zwisler@google.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