samedi 19 juin 2021

Crash with string and thread

I have a crash most probably due a string, I try to put the code logic exactly as it is. Please forgive me, but I don't want to share exactly the code as it is.. Where can be the vulnerability ? please help. Thank you. PS: SomeString which probably is the cause can is printed before and after the crash normally and it's value appears normally.

void M::handle(std::string const& SomeString)
{
    if (cond)
    {
        std::cout<<SomeString;
        thread= std::thread(
            [this, &SomeString]() mutable
            {
                callBack(SomeString);
            });
    }
    else
    {
       // Do something
    }
}

void M::Wa()
{   
   while (Flag)
    {
        {
            std::lock_guard<std::mutex> guard(g_mutex);

            Se se = Se();
            if (cond)
            {
                std::string SomeString(session_getName(se));
                auto it= someMap.find(SomeString);
                if (it!= someMap.end())
                { 
                      // do sometinhg
                }
                else
                {
                    handle(SomeString);
                }
            }
        }
        usleep(1);
    }

From traces this appear

std::enable_if<std::__and_<std::is_move_constructible<std::thread::id>, std::is_move_assignable<std::thread::id> >::value, void>::type std::swap<std::thread::id>(std::thread::id&, std::thread::id&)
move.h:191
std::thread::swap(std::thread&)
thread:161
std::thread::operator=(std::thread&&)
thread:155
handle(std::allocator<char> > const&) -- line where thread is 

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()
-- for this line: std::string SomeString(session_getName(se));

Aucun commentaire:

Enregistrer un commentaire