diff mbox series

[v3] kernel-shark: Fix a bug in KsPluginManager

Message ID 20190326133914.18884-1-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Commit 5def8aaffcdbb95c9ab5220ada0ae33db567c2b0
Headers show
Series [v3] kernel-shark: Fix a bug in KsPluginManager | expand

Commit Message

Yordan Karadzhov March 26, 2019, 1:39 p.m. UTC
const char *lib = plugin.toStdString().c_str();

This line is a bad idea because the returned array may (will) be
invalidated when the destructor of std::string is called.

Fixes: 18cf94f48 ("kernel-shark-qt: Add KernalShark Utils")
Suggested-by: Slavomir Kaslev <kaslevs@vmware.com>
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsUtils.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp
index 34b2e2d..3585cca 100644
--- a/kernel-shark/src/KsUtils.cpp
+++ b/kernel-shark/src/KsUtils.cpp
@@ -439,8 +439,8 @@  void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
 
 	auto lamRegUser = [&kshark_ctx](const QString &plugin)
 	{
-		const char *lib = plugin.toStdString().c_str();
-		kshark_register_plugin(kshark_ctx, lib);
+		std::string lib = plugin.toStdString();
+		kshark_register_plugin(kshark_ctx, lib.c_str());
 	};
 
 	_forEachInList(_ksPluginList,
@@ -474,8 +474,8 @@  void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 
 	auto lamUregUser = [&kshark_ctx](const QString &plugin)
 	{
-		const char *lib = plugin.toStdString().c_str();
-		kshark_unregister_plugin(kshark_ctx, lib);
+		std::string lib = plugin.toStdString();
+		kshark_unregister_plugin(kshark_ctx, lib.c_str());
 	};
 
 	_forEachInList(_ksPluginList,