Valgrind使用Stringstream

时间:2015-12-09 08:28:28

标签: c++ memory-leaks valgrind stringstream

我正在使用" std :: stringstream",用于转换" long"值为"十六进制字符串",以便在代码中进一步使用。

以下代码段:

void initDisplayVariant(){
    ...
    /// integer value to hex-string
    std::stringstream sstream;
    sstream << "0x"
            << std::setfill ('0') << std::setw(2)
    << std::hex << (int)frntDispVariant;
    std::string frntDispVariantHex = sstream.str();
    sstream.clear();    //clears out the stream-string
    ...
}

但是,valgrind列出了&#34;可到达泄漏的位置&#34;。

...
==6736== 0 bytes in 1 blocks are still reachable in loss record 1 of 143
==6736==    at 0x4024045: operator new[](unsigned int) (vg_replace_malloc.c:299)
==6736==    by 0x5232570: std::__numpunct_cache<char>::_M_cache(std::locale const&) (in /usr/lib/libstdc++.so.6.0.14)
==6736==    by 0x5236684: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (in /usr/lib/libstdc++.so.6.0.14)
==6736==    by 0x523678D: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (in /usr/lib/libstdc++.so.6.0.14)
==6736==    by 0x5241B43: std::ostream& std::ostream::_M_insert<long>(long) (in /usr/lib/libstdc++.so.6.0.14)
==6736==    by 0x5241CB4: std::ostream::operator<<(int) (in /usr/lib/libstdc++.so.6.0.14)
==6736==    by 0x808E76B: initDisplayVariant() (src.cpp:45)
...

由于流是方法本地的,并且不应该存在于方法范围之外(即使它在内部进行分配),因此报告泄漏的上下文不明确。

有任何线索或建议吗?

0 个答案:

没有答案