C++ &引用;已释放对象的校验和不正确;在图书馆';s析构函数

C++ &引用;已释放对象的校验和不正确;在图书馆';s析构函数,c++,C++,我试图对音频信号的各个部分进行一些测量(读作std::vector),这涉及到一些信号处理。我使用与中相同的函数计算MFCC常量,但不是使用Aquila::SineGenerator而是使用向量创建Aquila::SignalSource 删除无关代码后,我的功能是: void measure(std::vector<double> &output_vector, std::vector<double> &audio, int start_index, i

我试图对音频信号的各个部分进行一些测量(读作
std::vector
),这涉及到一些信号处理。我使用与中相同的函数计算MFCC常量,但不是使用
Aquila::SineGenerator
而是使用向量创建
Aquila::SignalSource

删除无关代码后,我的功能是:

void measure(std::vector<double> &output_vector, std::vector<double> &audio, int start_index, int end_index) {
    // Copy the 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 the MFCC constants.
    Aquila::SignalSource input(note_audio, 44100);
    Aquila::Mfcc mfcc(input.getSamplesCount());
    auto mfccValues = mfcc.calculate(input);

    // Copy them over to the output vector.
    for (int i = 0; i < mfccValues.size(); i++) {
        output_vector.push_back(mfccValues[i]);
    }
}
因此,我启动lldb并进行调试,在
malloc\u error\u break
处设置一个断点,并获得以下堆栈跟踪:

(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 at 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 at 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 at memory:1447
    frame #7: 0x000000010000297c prog-debug`std::__1::__vector_base<double, std::__1::allocator<double> >::~__vector_base(this=0x0000000100307878) + 380 at vector:476
    frame #8: 0x0000000100002e25 prog-debug`std::__1::vector<double, std::__1::allocator<double> >::~vector(this=0x0000000100307878) + 21 at vector:481
    frame #9: 0x0000000100002355 prog-debug`std::__1::vector<double, std::__1::allocator<double> >::~vector(this=0x0000000100307878) + 21 at 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 at measureVector.cpp:62
    frame #19: 0x0000000100018eb2 prog-debug`extractVectors(vectors=0x00007fff5fbfe4e0, audio=vector<double, std::__1::allocator<double> > at 0x00007fff5fbfe478, sample_rate=44100, bg_audio=vector<double, std::__1::allocator<double> > at 0x00007fff5fbfe460, bg_sample_rate=44100, notes=0x00007fff5fbfe490) + 3234 at extractVectors.cpp:74
    frame #20: 0x000000010002b915 prog-debug`train(results=0x00007fff5fbff620, training_path=std::__1::string at 0x00007fff5fbff608, bg_audio=vector<double, std::__1::allocator<double> > at 0x00007fff5fbff5f0, bg_sample_rate=44100, classes=0x00007fff5fbff638) + 5733 at train.cpp:44
    frame #21: 0x00000001000211d3 prog-debug`MUSE(input_path=std::__1::string at 0x00007fff5fbff948, training_path=std::__1::string at 0x00007fff5fbff930, noise_profile_path=std::__1::string at 0x00007fff5fbff908, output_path=std::__1::string at 0x00007fff5fbff8f0) + 995 at muse.cpp:44
    frame #22: 0x00000001000217fd prog-debug`main(argc=5, argv=0x00007fff5fbffab8) + 717 at muse.cpp:55
(lldb)bt
*线程#1:tid=0x23c194,0x00007fff8f487bc0 libsystem_malloc.dylib`malloc_error_break,queue='com.apple.main thread',停止原因=断点1.2
*帧#0:0x00007fff8f487bc0 libsystem_malloc.dylib`malloc_error_break
帧#1:0x00007fff8f4815c7 libsystem_malloc.dylib`szone_error+386
帧2:0x00007fff8f482e1a libsystem\u malloc.dylib`small\u free\u list\u remove\u ptr+291
帧#3:0x00007fff8f47f737 libsystem_malloc.dylib`szone_free_definite_size+3429
帧#4:0x00000001000029a5程序调试`std::uuu 1::uu向量基::~u向量基()[内联]std::u 1::u解除分配(uu ptr=0x00000001008f3800)+421新:164
帧#5:0x000000010000299c prog debug`std::uuu 1::uu vector_ubase::~u vector_ubase()[内联]std::u 1::分配器::解除分配(this=0x0000000100307888,u p=0x00000001008f3800,(null)=6300)+8在内存:1636
帧#6:0x0000000100002994 prog debug`std::uu 1::u vector_base::~u vector_base()[内联]std::u 1::分配器特征::在内存1447处取消分配(u a=0x0000000100307888,u p=0x00000001008f3800,u n=6300)+24
帧#7:0x000000010000297c prog debug`std::uuuu 1::uu向量u基::~u向量u基(此=0x0000000100307878)+380,向量:476
帧#8:0x0000000100002e25 prog debug`std::uu 1::vector::~vector(this=0x0000000100307878)+21在vector:481处
帧#9:0x0000000100002355 prog debug`std::uu 1::vector::~vector(this=0x0000000100307878)+21在vector:481处
帧#10:0x000000010004b99c prog debug`Aquila::MelFilter::~MelFilter()+28
帧#11:0x000000010004b975 prog debug`Aquila::MelFilter::~MelFilter()+21
帧#12:0x000000010004b8b7 prog debug`std::u 1::u向量_base),但它们都从
Aquila::Mfcc::calculate()
开始,通常似乎涉及析构函数。我遇到过类似的错误,这是由于试图返回基于堆栈的变量(oops-这就是我传入输出向量并在函数中修改它的原因),但我在这里看不到这一点-我正在使用它,然后将
double
值复制到我的输出向量。我试着用
new
创建
note\u audio
作为指针,我试着在堆栈和堆上创建一个数组而不是
std::vector
,但都没有效果


使用CMake和LLVM在OSXMavericks上构建C++11。根据评论中的建议,我保存了的要点(尽管它一直持续到>100个错误)。我在这里遗漏了什么?

我将这个问题发布到Aquila GitHub问题页面和图书馆的创建者那里。为了发现(好时机)


简而言之:Aquila使用的FFT库OOURAFT要求向量大小为2的幂,但如果不是这样,它不会抱怨,它只是在第一次调用
OOURAFT::FFT()
时写入释放的内存。外卖课程是在堆上发疯之前始终声明需要检查的条件。

提示:您只需编写
std::vector note\u音频(audio.begin()+start\u index,audio.begin()+end\u index)并且不需要进行复制,也不需要所有那些默认构造。您使用的是什么平台、编译器等。valgrind在您的系统上可用吗?如果是这样,运行它来获取有关内存滥用的详细信息。@DaleWilson:菜鸟错了,对不起!使用CMake和LLVM在OSXMavericks上构建C++11,我听说Valgrind没有在Mavericks()上工作,但也许是这样?(). 我会看看我是否能让它工作并报告回来。@DaleWilson:我运行了Valgrind,得到了很长的输出,看起来有很多错误(尽管我不知道如何解释它们)。前300行左右就是这个要点。我知道
地址0xa4a050是大小为25200 alloc'd的块后的0字节
通常指25200长度向量上25201位置的写入,但我不确定我在哪里指定了错误的长度。可能您的索引超出了输入向量的范围?
(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 at 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 at 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 at memory:1447
    frame #7: 0x000000010000297c prog-debug`std::__1::__vector_base<double, std::__1::allocator<double> >::~__vector_base(this=0x0000000100307878) + 380 at vector:476
    frame #8: 0x0000000100002e25 prog-debug`std::__1::vector<double, std::__1::allocator<double> >::~vector(this=0x0000000100307878) + 21 at vector:481
    frame #9: 0x0000000100002355 prog-debug`std::__1::vector<double, std::__1::allocator<double> >::~vector(this=0x0000000100307878) + 21 at 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 at measureVector.cpp:62
    frame #19: 0x0000000100018eb2 prog-debug`extractVectors(vectors=0x00007fff5fbfe4e0, audio=vector<double, std::__1::allocator<double> > at 0x00007fff5fbfe478, sample_rate=44100, bg_audio=vector<double, std::__1::allocator<double> > at 0x00007fff5fbfe460, bg_sample_rate=44100, notes=0x00007fff5fbfe490) + 3234 at extractVectors.cpp:74
    frame #20: 0x000000010002b915 prog-debug`train(results=0x00007fff5fbff620, training_path=std::__1::string at 0x00007fff5fbff608, bg_audio=vector<double, std::__1::allocator<double> > at 0x00007fff5fbff5f0, bg_sample_rate=44100, classes=0x00007fff5fbff638) + 5733 at train.cpp:44
    frame #21: 0x00000001000211d3 prog-debug`MUSE(input_path=std::__1::string at 0x00007fff5fbff948, training_path=std::__1::string at 0x00007fff5fbff930, noise_profile_path=std::__1::string at 0x00007fff5fbff908, output_path=std::__1::string at 0x00007fff5fbff8f0) + 995 at muse.cpp:44
    frame #22: 0x00000001000217fd prog-debug`main(argc=5, argv=0x00007fff5fbffab8) + 717 at muse.cpp:55