0
为什么valgrind会说在fclose()
调用中有内存泄漏?Valgrind在fclose检测到内存泄漏()
#include <stdio.h>
class Stream
{
public:
Stream();
~Stream();
private:
char* pszOutput;
size_t size;
FILE* file;
};
Stream::Stream()
{
file = open_memstream(&pszOutput, &size);
}
Stream::~Stream()
{
fclose(file);
}
int main()
{
Stream s;
return 0;
}
Valgrind的报告:
==52387== 1 bytes in 1 blocks are definitely lost in loss record 1 of 1
==52387== at 0x4C28CCE: realloc (vg_replace_malloc.c:632)
==52387== by 0x5639CA3: _IO_mem_finish (memstream.c:132)
==52387== by 0x5635956: [email protected]@GLIBC_2.2.5 (iofclose.c:66)
不要紧初始化pszOutput
或size
?或者,也许我需要添加其他东西?
你尝试过免费吗(pszOutput); ? – willll