std::streambuf から派生したクラスがあります。ただし、なぜ、どこで漏れているのかわかりません。私が使用しているツールによると、コードの最後のポイントは、このクラスのどこかにあります (ただし、行番号を抽出することはできません)。
クラスは、データを同期するストリームバッファをいくつでも保持できるという考え方です。(たとえば、std::cout と ofstream.rdbuf) すべての streambuf に書き込む std::endl を取得するまで、データを文字列に格納します。
メモリリークの可能性がある場所を教えてもらえますか?
これは私のヘッダーです:
#ifndef _MY_STREAM_BUF_H
#define _MY_STREAM_BUF_H
#include <iostream>
#include <algorithm>
#include <list>
#include "../../../Interface/EngineDefs.h"
namespace MyEngine
{
class MyStreamBuf : public std::streambuf
{
public:
MyStreamBuf();
~MyStreamBuf();
void AddStream(std::streambuf* sb);
void RemoveStream(std::streambuf* sb);
bool IsStreamAdded(std::streambuf* sb);
private:
std::list<std::streambuf*> mStreamBufs;
std::string mLine;
int32_t overflow(int32_t c);
int32_t sync();
};
}
#endif
cpp ファイル:
#include "../../../Include/Core/Logging/MyStreamBuf.h"
namespace MyEngine
{
MyStreamBuf::MyStreamBuf() : std::streambuf()
{
}
MyStreamBuf::~MyStreamBuf()
{
mStreamBufs.clear();
mLine.clear();
}
void MyStreamBuf::AddStream(std::streambuf* sb)
{
if (sb)
mStreamBufs.push_back(sb);
}
void MyStreamBuf::RemoveStream(std::streambuf* sb)
{
if (sb)
mStreamBufs.remove(sb);
}
bool MyStreamBuf::IsStreamAdded(std::streambuf* sb)
{
if (sb)
return (std::find(mStreamBufs.begin(),mStreamBufs.end(),sb) != mStreamBufs.end());
else
return false;
}
int32_t MyStreamBuf::overflow(int32_t c)
{
int32_t r1 = 0, r2 = 0;
if (c == EOF)
return !EOF;
else
{
mLine += c;
return r1 == EOF || r2 == EOF ? EOF : c;
}
}
int32_t MyStreamBuf::sync()
{
int32_t res = 0;
for(std::list<std::streambuf*>::iterator it = mStreamBufs.begin(); it != mStreamBufs.end(); ++it)
{
if (*it)
{
(*it)->sputn(mLine.c_str(),mLine.length());
res &= (*it)->pubsync();
}
}
mLine.clear();
return res == 0 ? 0 : -1;
}
}