david-m-rosen / SE-Sync

An implementation of the SE-Sync algorithm for synchronization over the special Euclidean group.
GNU Lesser General Public License v3.0
384 stars 83 forks source link

Memory Free issue on save #11

Closed StephenMcGill-TRI closed 6 years ago

StephenMcGill-TRI commented 6 years ago

Hello David,

I've be able to run the example code, but each time on exit, the problem tries to free unallocated memory. I'm not sure if this is a big deal, or not, but some relevant information is posted below. Thanks!

Here is the result of running lldb ./C++/build/bin/SE-Sync data/CSAIL.g2o

===== END SE-SYNC =====

Saving final poses to file: poses.txt
SE-Sync(24330,0x7fff98f93380) malloc: *** error for object 0xbfd00f9944bcb218: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Process 24330 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff60ab6b6e libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff60ab6b6e <+10>: jae    0x7fff60ab6b78            ; <+20>
    0x7fff60ab6b70 <+12>: movq   %rax, %rdi
    0x7fff60ab6b73 <+15>: jmp    0x7fff60aadb00            ; cerror_nocancel
    0x7fff60ab6b78 <+20>: retq   
Target 0: (SE-Sync) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff60ab6b6e libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff60c81080 libsystem_pthread.dylib`pthread_kill + 333
    frame #2: 0x00007fff60a121ae libsystem_c.dylib`abort + 127
    frame #3: 0x00007fff60b10822 libsystem_malloc.dylib`free + 521
    frame #4: 0x000000010000432d SE-Sync`main [inlined] Eigen::internal::handmade_aligned_free(void*) at Memory.h:98 [opt]
    frame #5: 0x000000010000431f SE-Sync`main [inlined] Eigen::internal::aligned_free(void*) at Memory.h:179 [opt]
    frame #6: 0x000000010000431f SE-Sync`main [inlined] void Eigen::internal::conditional_aligned_free<true>(void*) at Memory.h:230 [opt]
    frame #7: 0x000000010000431f SE-Sync`main [inlined] void Eigen::internal::conditional_aligned_delete_auto<double, true>(ptr=<unavailable>) at Memory.h:416 [opt]
    frame #8: 0x000000010000431f SE-Sync`main [inlined] Eigen::DenseStorage<double, -1, -1, 1, 0>::~DenseStorage() at DenseStorage.h:542 [opt]
    frame #9: 0x000000010000431b SE-Sync`main [inlined] Eigen::DenseStorage<double, -1, -1, 1, 0>::~DenseStorage() at DenseStorage.h:542 [opt]
    frame #10: 0x000000010000431b SE-Sync`main [inlined] Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::~PlainObjectBase() at PlainObjectBase.h:98 [opt]
    frame #11: 0x000000010000431b SE-Sync`main [inlined] Eigen::Matrix<double, -1, 1, 0, -1, 1>::~Matrix() at Matrix.h:178 [opt]
    frame #12: 0x000000010000431b SE-Sync`main [inlined] Eigen::Matrix<double, -1, 1, 0, -1, 1>::~Matrix() at Matrix.h:178 [opt]
    frame #13: 0x000000010000431b SE-Sync`main [inlined] SESync::RelativePoseMeasurement::~RelativePoseMeasurement(this=<unavailable>) at RelativePoseMeasurement.h:17 [opt]
    frame #14: 0x000000010000431b SE-Sync`main [inlined] SESync::RelativePoseMeasurement::~RelativePoseMeasurement(this=<unavailable>) at RelativePoseMeasurement.h:17 [opt]
    frame #15: 0x000000010000431b SE-Sync`main [inlined] std::__1::allocator<SESync::RelativePoseMeasurement>::destroy(__p=<unavailable>) at memory:1838 [opt]
    frame #16: 0x000000010000431b SE-Sync`main [inlined] void std::__1::allocator_traits<std::__1::allocator<SESync::RelativePoseMeasurement> >::__destroy<SESync::RelativePoseMeasurement>(__p=<unavailable>) at memory:1706 [opt]
    frame #17: 0x000000010000431b SE-Sync`main [inlined] void std::__1::allocator_traits<std::__1::allocator<SESync::RelativePoseMeasurement> >::destroy<SESync::RelativePoseMeasurement>(__p=<unavailable>) at memory:1574 [opt]
    frame #18: 0x000000010000431b SE-Sync`main [inlined] std::__1::__vector_base<SESync::RelativePoseMeasurement, std::__1::allocator<SESync::RelativePoseMeasurement> >::__destruct_at_end(__new_last=0x0000000100357000) at vector:417 [opt]
    frame #19: 0x00000001000042fe SE-Sync`main [inlined] std::__1::__vector_base<SESync::RelativePoseMeasurement, std::__1::allocator<SESync::RelativePoseMeasurement> >::clear() at vector:361 [opt]
    frame #20: 0x00000001000042fe SE-Sync`main [inlined] std::__1::__vector_base<SESync::RelativePoseMeasurement, std::__1::allocator<SESync::RelativePoseMeasurement> >::~__vector_base() at vector:444 [opt]
    frame #21: 0x00000001000042f2 SE-Sync`main [inlined] std::__1::vector<SESync::RelativePoseMeasurement, std::__1::allocator<SESync::RelativePoseMeasurement> >::~vector() at vector:450 [opt]
    frame #22: 0x00000001000042f2 SE-Sync`main [inlined] std::__1::vector<SESync::RelativePoseMeasurement, std::__1::allocator<SESync::RelativePoseMeasurement> >::~vector() at vector:450 [opt]
    frame #23: 0x00000001000042f2 SE-Sync`main(argc=<unavailable>, argv=<unavailable>) at main.cpp:40 [opt]
    frame #24: 0x00007fff60966015 libdyld.dylib`start + 1
    frame #25: 0x00007fff60966015 libdyld.dylib`start + 1

From a previous build, running lldb ./C++/build/bin/SE-Sync data/kitti_00.g2o:

* * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x101a52ff8)
    frame #0: 0x0000000100005b2f SE-Sync`SESync::SESyncResult::~SESyncResult() [inlined] Eigen::internal::handmade_aligned_free(void*) at Memory.h:98 [opt]
   95   /** \internal Frees memory allocated with handmade_aligned_malloc */
   96   inline void handmade_aligned_free(void *ptr)
   97   {
-> 98     if (ptr) std::free(*(reinterpret_cast<void**>(ptr) - 1));
   99   }
   100  
   101  /** \internal

System: macOS 10.13.4 Compiler: clang --version

clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm@4/bin

Debugger: lldb --version

lldb-902.0.79.2
  Swift-4.1
david-m-rosen commented 6 years ago

Hey Stephen!

Apologies for the long delay in getting back to you -- was on travel earlier this week and didn't have a whole lot of time to dig into this.

As far as I can tell, this issue is related to Eigen's vectorization of fixed-size types. I've traced the problem back to the memory that is allocated when reading in pose-graph SLAM problems from .g2o files on disk (in the function read_g2o_file()). I've been able to correct this bug on my system by turning on an (erroneously commented-out) compiler flag to enable vectorization in the top-level CMake file -- please let me know if this fixes the problem for you?

Thanks!