aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYordan Karadzhov (VMware) <y.karadz@gmail.com>2021-02-11 12:31:40 +0200
committerYordan Karadzhov (VMware) <y.karadz@gmail.com>2021-02-16 10:25:14 +0200
commitc1f920aaa1bad3031b097995fd3992e070b4f826 (patch)
treef0b55b686d7cc29f4a4a0794a70edf6f307714da
parent0f6a0d523e8ae7b0962e2c0fee8cc1bc1eb6bcbc (diff)
downloadkernel-shark-c1f920aaa1bad3031b097995fd3992e070b4f826.tar.gz
kernel-shark: Do proper reset in kshark_close_all()
The function is supposed to close all Data streams and reset the session context object (kshark_ctx). However, this is not happening completely, because after closing the individual streams, the context still contains the history of all closed stream Ids, recorded inside the array of data stream descriptors. In this patch we add a proper resetting of this array and its info descriptor. Link: https://lore.kernel.org/linux-trace-devel/20210211103205.418588-3-y.karadz@gmail.com Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
-rw-r--r--src/libkshark.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libkshark.c b/src/libkshark.c
index c57ca01f..dc58dcf6 100644
--- a/src/libkshark.c
+++ b/src/libkshark.c
@@ -37,6 +37,7 @@ static bool kshark_default_context(struct kshark_context **context)
kshark_ctx->stream = calloc(KS_DEFAULT_NUM_STREAMS,
sizeof(*kshark_ctx->stream));
kshark_ctx->stream_info.array_size = KS_DEFAULT_NUM_STREAMS;
+ kshark_ctx->stream_info.next_free_stream_id = 0;
kshark_ctx->stream_info.max_stream_id = -1;
/* Will free kshark_context_handler. */
@@ -484,10 +485,22 @@ int kshark_close(struct kshark_context *kshark_ctx, int sd)
*/
void kshark_close_all(struct kshark_context *kshark_ctx)
{
+ size_t mem_reset_size;
int i;
+ if (kshark_ctx->stream_info.max_stream_id < 0)
+ return;
+
for (i = 0; i <= kshark_ctx->stream_info.max_stream_id; ++i)
kshark_close(kshark_ctx, i);
+
+ /* Reset the array of data stream descriptors. */
+ mem_reset_size = (kshark_ctx->stream_info.max_stream_id + 1 ) *
+ sizeof(*kshark_ctx->stream);
+ memset(kshark_ctx->stream, 0, mem_reset_size);
+
+ kshark_ctx->stream_info.next_free_stream_id = 0;
+ kshark_ctx->stream_info.max_stream_id = -1;
}
/**