Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'double free or corruption (out)' when running example code with libcmaes as shared library #190

Closed
saihv opened this issue Nov 18, 2018 · 2 comments

Comments

@saihv
Copy link

saihv commented Nov 18, 2018

I am trying to use libcmaes.so as a shared library through CMake, so I installed it to a specific location and imported it into my own project using the location as below:

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -mfma")

add_library(libcmaes SHARED IMPORTED)
set_property(TARGET libcmaes PROPERTY IMPORTED_LOCATION "libcmaes/install/lib/libcmaes.so")

target_link_libraries(nbvplanner libcmaes)

In my project, I tried to run the sample code that's given in the README. While the code appears to run successfully, I get a 'double free or corruption' error at termination.

Output:

best solution: best solution => f-value=2.52029e-15 / fevals=2810 / sigma=1.91516e-07 / iter=281 / elaps=7ms / x= 2.14112e-08 -1.14725e-08 -1.84194e-08  1.60249e-08  1.65269e-08 -1.96509e-08 -1.07566e-09 -2.31984e-09  2.53547e-08  5.04625e-09
optimization took 0.007 seconds
*** Error in `./nbvplanner': double free or corruption (out): 0x0000000001202320 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f46e0bbe7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f46e0bc737a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f46e0bcb53c]
/home/sai/code/nbvplanner/lib/libcmaes/install/lib/libcmaes.so.0(_ZN8libcmaes12CMASolutionsD1Ev+0x13)[0x7f46e16e91b3]

First few lines of valgrind output:

best solution: best solution => f-value=4.71486e-16 / fevals=2980 / sigma=1.10926e-07 / iter=298 / elaps=336ms / x=-7.32494e-10  6.19359e-09 -5.35323e-09  4.65318e-10  5.68156e-10  1.07733e-08  1.03594e-08 -7.60523e-09  8.57882e-09 -6.96962e-09
optimization took 0.336 seconds
==7953== Invalid free() / delete / delete[] / realloc()
==7953==    at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7953==    by 0x507A1B2: libcmaes::CMASolutions::~CMASolutions() (in /home/sai/code/nbvplanner/lib/libcmaes/install/lib/libcmaes.so.0.0.0)
==7953==    by 0x4112B1: main (in /home/sai/code/nbvplanner/build/nbvplanner)
==7953==  Address 0x6e785c0 is 32 bytes inside a block of size 112 alloc'd
==7953==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7953==    by 0x4156BF: libcmaes::CMASolutions::CMASolutions(libcmaes::CMASolutions const&) (in /home/sai/code/nbvplanner/build/nbvplanner)
==7953==    by 0x416391: libcmaes::CMASolutions libcmaes::cmaes<libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy> >(std::function<double (double const*, int const&)>&, libcmaes::CMAParameters<libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy> >&, std::function<int (libcmaes::CMAParameters<libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy> > const&, libcmaes::CMASolutions const&)>&, std::function<Eigen::Matrix<double, -1, 1, 0, -1, 1> (double const*, int const&)>, libcmaes::CMASolutions const&, std::function<int (libcmaes::CMAParameters<libcmaes::GenoPheno<libcmaes::NoBoundStrategy, libcmaes::NoScalingStrategy> > const&, libcmaes::CMASolutions const&, std::basic_ofstream<char, std::char_traits<char> >&)>&) (in /home/sai/code/nbvplanner/build/nbvplanner)
==7953==    by 0x4111D8: main (in /home/sai/code/nbvplanner/build/nbvplanner)
==7953== 

I was wondering if anyone had any idea why this might be happening?

@beniz
Copy link
Collaborator

beniz commented Nov 19, 2018

Hi, you might want to remove the -mfma just in case it gets in the way. Other than that you may want to share the nvbplanner code so see how you are using the lib.

@saihv
Copy link
Author

saihv commented Nov 19, 2018

Removing -mfma did the trick (I thought that was needed because it was mentioned in some other issues regarding seg faults, but apparently not). Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants