c++ - "Incorrect checksum for freed object" in library's destructors -
i'm trying measurements on sections of audio signal (read std::vector<double>
) involves signal-processing using aquila. i'm calculating mfcc constants using same functions in their example, instead of aquila::sinegenerator
i'm creating aquila::signalsource
vector, using constructor.
my function, irrelevant code removed, is:
void measure(std::vector<double> &output_vector, std::vector<double> &audio, int start_index, int end_index) { // copy raw note over. std::vector<double> note_audio(end_index - start_index); std::copy(audio.begin() + start_index, audio.begin() + end_index, note_audio.begin()); // calculate mfcc constants. aquila::signalsource input(note_audio, 44100); aquila::mfcc mfcc(input.getsamplescount()); auto mfccvalues = mfcc.calculate(input); // copy them on output vector. (int = 0; < mfccvalues.size(); i++) { output_vector.push_back(mfccvalues[i]); } }
when run - often, not always, second or third time it's called - crashes , outputs:
prog(15384,0x7fff7cafb310) malloc: *** error object 0x7f8781863208: incorrect checksum freed object - object modified after being freed. *** set breakpoint in malloc_error_break debug abort trap: 6
so, fire lldb , debug, setting breakpoint @ malloc_error_break
, , stacktrace:
(lldb) bt * thread #1: tid = 0x23c194, 0x00007fff8f487bc0 libsystem_malloc.dylib`malloc_error_break, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2 * frame #0: 0x00007fff8f487bc0 libsystem_malloc.dylib`malloc_error_break frame #1: 0x00007fff8f4815c7 libsystem_malloc.dylib`szone_error + 386 frame #2: 0x00007fff8f482e1a libsystem_malloc.dylib`small_free_list_remove_ptr + 291 frame #3: 0x00007fff8f47f737 libsystem_malloc.dylib`szone_free_definite_size + 3429 frame #4: 0x00000001000029a5 prog-debug`std::__1::__vector_base<double, std::__1::allocator<double> >::~__vector_base() [inlined] std::__1::__deallocate(__ptr=0x00000001008f3800) + 421 @ new:164 frame #5: 0x000000010000299c prog-debug`std::__1::__vector_base<double, std::__1::allocator<double> >::~__vector_base() [inlined] std::__1::allocator<double>::deallocate(this=0x0000000100307888, __p=0x00000001008f3800, (null)=6300) + 8 @ memory:1636 frame #6: 0x0000000100002994 prog-debug`std::__1::__vector_base<double, std::__1::allocator<double> >::~__vector_base() [inlined] std::__1::allocator_traits<std::__1::allocator<double> >::deallocate(__a=0x0000000100307888, __p=0x00000001008f3800, __n=6300) + 24 @ memory:1447 frame #7: 0x000000010000297c prog-debug`std::__1::__vector_base<double, std::__1::allocator<double> >::~__vector_base(this=0x0000000100307878) + 380 @ vector:476 frame #8: 0x0000000100002e25 prog-debug`std::__1::vector<double, std::__1::allocator<double> >::~vector(this=0x0000000100307878) + 21 @ vector:481 frame #9: 0x0000000100002355 prog-debug`std::__1::vector<double, std::__1::allocator<double> >::~vector(this=0x0000000100307878) + 21 @ vector:481 frame #10: 0x000000010004b99c prog-debug`aquila::melfilter::~melfilter() + 28 frame #11: 0x000000010004b975 prog-debug`aquila::melfilter::~melfilter() + 21 frame #12: 0x000000010004b8b7 prog-debug`std::__1::__vector_base<aquila::melfilter, std::__1::allocator<aquila::melfilter> >::~__vector_base() + 279 frame #13: 0x000000010004b795 prog-debug`std::__1::vector<aquila::melfilter, std::__1::allocator<aquila::melfilter> >::~vector() + 21 frame #14: 0x000000010004b775 prog-debug`std::__1::vector<aquila::melfilter, std::__1::allocator<aquila::melfilter> >::~vector() + 21 frame #15: 0x000000010004b755 prog-debug`aquila::melfilterbank::~melfilterbank() + 21 frame #16: 0x000000010004b545 prog-debug`aquila::melfilterbank::~melfilterbank() + 21 frame #17: 0x000000010004b463 prog-debug`aquila::mfcc::calculate(aquila::signalsource const&, unsigned long) + 323 frame #18: 0x00000001000203b6 prog-debug`measure(the_vector=0x00007fff5fbfd8c8, audio=0x00007fff5fbfe478, start_index=7078, end_index=13378) + 1270 @ measurevector.cpp:62 frame #19: 0x0000000100018eb2 prog-debug`extractvectors(vectors=0x00007fff5fbfe4e0, audio=vector<double, std::__1::allocator<double> > @ 0x00007fff5fbfe478, sample_rate=44100, bg_audio=vector<double, std::__1::allocator<double> > @ 0x00007fff5fbfe460, bg_sample_rate=44100, notes=0x00007fff5fbfe490) + 3234 @ extractvectors.cpp:74 frame #20: 0x000000010002b915 prog-debug`train(results=0x00007fff5fbff620, training_path=std::__1::string @ 0x00007fff5fbff608, bg_audio=vector<double, std::__1::allocator<double> > @ 0x00007fff5fbff5f0, bg_sample_rate=44100, classes=0x00007fff5fbff638) + 5733 @ train.cpp:44 frame #21: 0x00000001000211d3 prog-debug`muse(input_path=std::__1::string @ 0x00007fff5fbff948, training_path=std::__1::string @ 0x00007fff5fbff930, noise_profile_path=std::__1::string @ 0x00007fff5fbff908, output_path=std::__1::string @ 0x00007fff5fbff8f0) + 995 @ muse.cpp:44 frame #22: 0x00000001000217fd prog-debug`main(argc=5, argv=0x00007fff5fbffab8) + 717 @ muse.cpp:55
sometimes that, other errors in internals (you can see them here), start @ aquila::mfcc::calculate()
, seem involve destructor. i've run errors similar , due trying return stack-based variables (oops - it's why i'm passing in output_vector , modifying in function), don't see here - i'm using it, copying on double
values output vector. i've tried creating note_audio
pointer new
, i've tried creating array instead of std::vector
both on stack , on heap, no avail.
building c++11 on os x mavericks, using cmake , llvm. per suggestion in comments, i've saved gist of the first ~300 lines of valgrind output (although keeps going until >100 errors). missing here?
i posted question aquila github issues page , got answer library's creator. credit goes issue discovery (good timing).
in short: oourafft, fft library used aquila, requires vector size power of 2, doesn't complain if that's not case, writes deallocated memory on first call oourafft::fft()
. take-away lesson assert conditions need check before going crazy on heap.
Comments
Post a Comment