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