gpt4 book ai didi

c++ - Valgrind 内存泄漏错误的文件跟踪

转载 作者:行者123 更新时间:2023-11-30 04:01:57 25 4
gpt4 key购买 nike

我目前正处于调试的内存泄漏检测阶段,正在我的可执行文件上运行 valgrind --leak-check=full --show-leak-kinds=all。但是,我在损失记录中得到了一些令人困惑的输出:

==26628== 2 bytes in 1 blocks are indirectly lost in loss record 2 of 343
==26628== at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26628== by 0x436EF6: void std::vector<unsigned char, std::allocator<unsigned char> >::_M_range_insert<char*>(__gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsig$
==26628== by 0x4368EF: giga::Page::aux_load() (stl_vector.h:1291)
==26628== by 0x43499D: cachepp::SerialCache<cachepp::SimpleSerialCacheData, giga::Page>::allocate(std::shared_ptr<giga::Page> const&) (lineinterface.template:34)
...

问题出在 giga::Page::aux_load 的跟踪中——这个函数是我定义的,绝对在标准库中。我不确定为什么相应的调用文件的输出行没有报告该行。

我不确定这是否需要代码,但万一我需要 --

void giga::Page::aux_load() {
this->data.clear();
// deallocate the data vector
std::vector<uint8_t>().swap(this->data);

if(!this->get_is_dirty()) {
// load data into the page
FILE *fp = fopen(this->get_filename().c_str(), "r");
if(fseek(fp, this->file_offset, SEEK_SET) == -1) {
throw(exceptionpp::RuntimeError("giga::Page::aux_load", "invalid result returned from fseek"));
}

char *data = (char *) calloc(this->get_size(), sizeof(char));

if(fread((void *) data, sizeof(char), this->get_size(), fp) < this->get_size()) {
throw(exceptionpp::RuntimeError("giga::Page::aux_load", "invalid result returned from fread"));
}
fclose(fp);

this->data.insert(this->data.end(), data, data + this->get_size());

free((void *) data);
}
}

如有任何帮助,我们将不胜感激!

最佳答案

这很可能是由于 valgrind stacktrace 没有显示内联函数调用引起的在 STL_vector.h:1291 中定义并在 aux_load 中的某处调用。

下一版本的 Valgrind 支持显示内联函数,使用选项 --read-inline-info=yes。

所以,获取并编译最新的valgrind svn版本参见 http://www.valgrind.org/downloads/repository.html有关如何获取、配置和编译 valgrind svn 版本的说明

关于c++ - Valgrind 内存泄漏错误的文件跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25468959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com