diff mbox series

[2/2] kernel-shark: Fix memory corruption in KsCaptureDialog

Message ID 20220411151744.445930-2-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit 2ae9cbb8d2457898b6fa7b6429854f33541be222
Headers show
Series [1/2] kernel-shark: Do not hard-code app name | expand

Commit Message

Yordan Karadzhov April 11, 2022, 3:17 p.m. UTC
The list of local plugins, returned by tracefs_tracers() must be freed using tracefs_list_free().

Reported-by: yinkui.zhang@xedge.ai
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsCaptureDialog.cpp | 6 ++----
 src/libkshark-tepdata.c | 5 +++++
 src/libkshark-tepdata.h | 2 ++
 3 files changed, 9 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/src/KsCaptureDialog.cpp b/src/KsCaptureDialog.cpp
index ca4c2bc..651f811 100644
--- a/src/KsCaptureDialog.cpp
+++ b/src/KsCaptureDialog.cpp
@@ -222,12 +222,10 @@  QStringList KsCaptureControl::_getPlugins()
 	if (!all_tracers)
 		return pluginList;
 
-	for (int i = 0; all_tracers[i]; ++i) {
+	for (int i = 0; all_tracers[i]; ++i)
 		pluginList << all_tracers[i];
-		free(all_tracers[i]);
-	}
 
-	free(all_tracers);
+	kshark_tracecmd_plugin_list_free(all_tracers);
 	std::sort(pluginList.begin(), pluginList.end());
 
 	return pluginList;
diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c
index 08aca09..b435a29 100644
--- a/src/libkshark-tepdata.c
+++ b/src/libkshark-tepdata.c
@@ -1724,6 +1724,11 @@  char **kshark_tracecmd_local_plugins()
 	return tracefs_tracers(tracefs_tracing_dir());
 }
 
+void kshark_tracecmd_plugin_list_free(char **list)
+{
+	tracefs_list_free(list);
+}
+
 /**
  * @brief Free an array, allocated by kshark_tracecmd_get_hostguest_mapping() API
  *
diff --git a/src/libkshark-tepdata.h b/src/libkshark-tepdata.h
index 1b955be..c67c06b 100644
--- a/src/libkshark-tepdata.h
+++ b/src/libkshark-tepdata.h
@@ -51,6 +51,8 @@  void kshark_tep_filter_reset(struct kshark_data_stream *stream);
 
 char **kshark_tracecmd_local_plugins();
 
+void kshark_tracecmd_plugin_list_free(char **list);
+
 struct tep_handle;
 
 struct tep_handle *kshark_get_tep(struct kshark_data_stream *stream);