* [PATCH] libtraceeval: Do not just copy vals for delta elements
@ 2023-10-11 3:02 Steven Rostedt
0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2023-10-11 3:02 UTC (permalink / raw)
To: Linux Trace Devel; +Cc: Ross Zwisler
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-11 3:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 3:02 [PATCH] libtraceeval: Do not just copy vals for delta elements Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox