diff mbox series

[v2,02/27] kernel-shark: Do proper reset in kshark_close_all()

Message ID 20210211103205.418588-3-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit c1f920aaa1bad3031b097995fd3992e070b4f826
Headers show
Series Complete the KernelShark v2 transformation | expand

Commit Message

Yordan Karadzhov Feb. 11, 2021, 10:31 a.m. UTC
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.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/libkshark.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/src/libkshark.c b/src/libkshark.c
index c57ca01..dc58dcf 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;
 }
 
 /**