Skip to contentSkip to conversation

kernel-shark: Fix a bug in KsPluginManager

PATCH New Yordan Karadzhov 1 participant 1 message Mar 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 kernel-shark: Fix a bug in KsPluginManager

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")
---
 kernel-shark/src/KsUtils.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel-shark/src/KsUtils.cpp +4 -4
index 34b2e2d..3585cca 100644
@@ -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,
Signature · 1 line
2.19.1