Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 7, 2019 at 5:44 PM Yordan Karadzhov <ykaradzhov@xxxxxxxxxx> wrote:
>
> 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.
>
> Signed-off-by: Yordan Karadzhov <ykaradzhov@xxxxxxxxxx>
> ---
>  kernel-shark/src/KsUtils.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp
> index 34b2e2d..d7b1753 100644
> --- a/kernel-shark/src/KsUtils.cpp
> +++ b/kernel-shark/src/KsUtils.cpp
> @@ -439,7 +439,7 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
>
>         auto lamRegUser = [&kshark_ctx](const QString &plugin)
>         {
> -               const char *lib = plugin.toStdString().c_str();
> +               const char *lib = plugin.toLocal8Bit().data();
>                 kshark_register_plugin(kshark_ctx, lib);
>         };
>
> @@ -474,7 +474,7 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
>
>         auto lamUregUser = [&kshark_ctx](const QString &plugin)
>         {
> -               const char *lib = plugin.toStdString().c_str();
> +               const char *lib = plugin.toLocal8Bit().data();
>                 kshark_unregister_plugin(kshark_ctx, lib);
>         };

Doesn't the new version have the same problem with the temporary QByteArray?

How about saving the data in a local std::string/QByteArray variable?

               std::string lib = plugin.toStdString();
               kshark_register_plugin(kshark_ctx, lib.c_str());

Thanks!


--
Slavomir Kaslev



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux