C++ Valgrind在fclose()检测到内存泄漏

C++ Valgrind在fclose()检测到内存泄漏,c++,valgrind,fclose,C++,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

为什么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;
}
初始化
pszOutput
size
是否重要?或者我需要添加其他内容?

来自:

函数的作用是:打开一个流以写入缓冲区。缓冲区是动态分配的(与malloc(3)一样),并根据需要自动增长。关闭流后,调用方应释放(3)此缓冲区

因此,根据这一点,您需要在关闭文件描述符后释放(pszOutput)。

来自:

函数的作用是:打开一个流以写入缓冲区。缓冲区是动态分配的(与malloc(3)一样),并根据需要自动增长。关闭流后,调用方应释放(3)此缓冲区


因此,在关闭文件描述符后,需要释放(pszOutput)

是否尝试释放(pszOutput)?你试过释放(pszOutput)?谢谢,朋友。这真的很有帮助。谢谢,朋友。这真的很有帮助。
==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: fclose@@GLIBC_2.2.5 (iofclose.c:66)