1

thats the first time i'am programming in C++ and using Valgrind to find memoryleaks etc. I get errors I can'not understand. Can anyone help me please?

I should say that its possible that diffrent threads are calling this function!

The command I'am starting Valgrind is:

 valgrind -v --leak-check=full --show-reachable=yes --trace-children=yes --tool=memcheck --suppressions=../valgrind.supp ./my_app

And these are the errors:

==14404==    at 0x4C25F98: memcpy (mc_replace_strmem.c:497)
==14404==    by 0x57252F5: std::string::append(char const*, unsigned long) (in /usr/lib/libstdc++.so.6.0.13)
==14404==    by 0x430F26: DriverManager::GetPathById(char const*) (driver_manager.cpp:138)
==14404==    by 0x43064A: DriverManager::UnloadDriver(Driver*) (driver_manager.cpp:31)
==14404==    by 0x430DC6: DriverManager::UnloadDrivers() (driver_manager.cpp:115)
==14404==    by 0x4279AA: Application::~Application() (application.cpp:134)
==14404==    by 0x607A611: __run_exit_handlers (exit.c:78)
==14404==    by 0x607A664: exit (exit.c:100)
==14404==    by 0x6062C93: (below main) (libc-start.c:260)
==14404==  Address 0x6a20f6b is 27 bytes inside a block of size 29 free'd
==14404==    at 0x4C23E0F: operator delete(void*) (vg_replace_malloc.c:387)
==14404==    by 0x5724EE8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/libstdc++.so.6.0.13)
==14404==    by 0x607A611: __run_exit_handlers (exit.c:78)
==14404==    by 0x607A664: exit (exit.c:100)
==14404==    by 0x6062C93: (below main) (libc-start.c:260)
==14404==
==14404==
==14404== 1 errors in context 5 of 6:
==14404== Invalid read of size 1
==14404==    at 0x4C25812: __GI_strlen (mc_replace_strmem.c:284)
==14404==    by 0x572538B: std::string::append(char const*) (in /usr/lib/libstdc++.so.6.0.13)
==14404==    by 0x430F26: DriverManager::GetPathById(char const*) (driver_manager.cpp:138)
==14404==    by 0x43064A: DriverManager::UnloadDriver(Driver*) (driver_manager.cpp:31)
==14404==    by 0x430DC6: DriverManager::UnloadDrivers() (driver_manager.cpp:115)
==14404==    by 0x4279AA: Application::~Application() (application.cpp:134)
==14404==    by 0x607A611: __run_exit_handlers (exit.c:78)
==14404==    by 0x607A664: exit (exit.c:100)
==14404==    by 0x6062C93: (below main) (libc-start.c:260)
==14404==  Address 0x6a20f68 is 24 bytes inside a block of size 29 free'd
==14404==    at 0x4C23E0F: operator delete(void*) (vg_replace_malloc.c:387)
==14404==    by 0x5724EE8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/libstdc++.so.6.0.13)
==14404==    by 0x607A611: __run_exit_handlers (exit.c:78)
==14404==    by 0x607A664: exit (exit.c:100)
==14404==    by 0x6062C93: (below main) (libc-start.c:260)
==14404==
==14404==
==14404== 4 errors in context 6 of 6:
==14404== Invalid read of size 1
==14404==    at 0x4C25824: __GI_strlen (mc_replace_strmem.c:284)
==14404==    by 0x572538B: std::string::append(char const*) (in /usr/lib/libstdc++.so.6.0.13)
==14404==    by 0x430F26: DriverManager::GetPathById(char const*) (driver_manager.cpp:138)
==14404==    by 0x43064A: DriverManager::UnloadDriver(Driver*) (driver_manager.cpp:31)
==14404==    by 0x430DC6: DriverManager::UnloadDrivers() (driver_manager.cpp:115)
==14404==    by 0x4279AA: Application::~Application() (application.cpp:134)
==14404==    by 0x607A611: __run_exit_handlers (exit.c:78)
==14404==    by 0x607A664: exit (exit.c:100)
==14404==    by 0x6062C93: (below main) (libc-start.c:260)
==14404==  Address 0x6a20f69 is 25 bytes inside a block of size 29 free'd
==14404==    at 0x4C23E0F: operator delete(void*) (vg_replace_malloc.c:387)
==14404==    by 0x5724EE8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/libstdc++.so.6.0.13)
==14404==    by 0x607A611: __run_exit_handlers (exit.c:78)
==14404==    by 0x607A664: exit (exit.c:100)
==14404==    by 0x6062C93: (below main) (libc-start.c:260)

And thats the GetDriverPathById()-Function:

string DriverManager::GetPathById(const char* id) {
    string path;

    path.assign(driverPath);
    path.append(id);
    path.append(".so");

    return path;
}

And thats the way I'am calling this function:

GetPathById( obj->GetDriverId()->c_str() );

Obj is an instantiated class of a shared object. And GetDriverId() gives me a string* to:

const string Driver::id = "test";

driverPath is:

string DriverManager::driverPath;

0 Answers0