函数boost :: filesystem :: complete被valgrind报告为可能的内存泄漏

时间:2012-03-22 20:42:47

标签: c++ boost

我的代码看起来像

void Image::Init(std::string _filename)
{
  boost::filesystem::path filepath(_filename);
  boost::filesystem::path realpath = boost::filesystem::complete(filepath);  //leak point
  ...
}

出于某种原因,valgrind报告上面评论的行正在泄漏。 这是“可能丢失”的报告之一。 尽管如此,我想弄清楚为什么它可能会丢失。 我正在使用boost版本1.38。 Valgrind 3.7。我的操作系统是linux 2.6.29

valgrind输出如下所示:

==32009== 471 bytes in 3 blocks are possibly lost in loss record 161 of 174
==32009==    at 0x40220EE: malloc (vg_replace_malloc.c:263)
==32009==    by 0x84DAC61: operator new(unsigned int) (ZeroNew.cpp:11)
==32009==    by 0x44C79DA: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.8)
==32009==    by 0x44C8947: std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==32009==    by 0x44CA3A7: std::string::reserve(unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==32009==    by 0x44CA9E3: std::string::operator+=(char) (in /usr/lib/libstdc++.so.6.0.8)
==32009==    by 0x829189A: boost::filesystem::basic_path<std::string, boost::filesystem::path_traits>::m_append(char) (path.hpp:1079)
==32009==    by 0x829193C: boost::filesystem::basic_path<std::string, boost::filesystem::path_traits>::operator/=(char const*) (path.hpp:1099)
==32009==    by 0x8291977: boost::filesystem::basic_path<std::string, boost::filesystem::path_traits>::operator/=(boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> const&) (path.hpp:203)
==32009==    by 0x8296F24: boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> boost::filesystem::operator/<std::string, boost::filesystem::path_traits>(boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> const&, boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> const&) (path.hpp:521)
==32009==    by 0x829AB20: boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> >, boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> >::type boost::filesystem::complete<boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> const&, boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> const&) (operations.hpp:586)
==32009==    by 0x829C41E: boost::filesystem::complete(boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> const&) (operations.hpp:752)
==32009==    by 0x849AF2D: Image::Init(std::string, int) (Image.cpp:50)

我很好奇,如果有人知道为什么会发生这种情况,或者在版本1.38版本中这个代码中只有一个错误。如果可以使用稍微不同的语法,那就太棒了。

感谢。

0 个答案:

没有答案