mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 06:53:52 +00:00
Avoid possible memory leak by using the unique_ptr
This commit is contained in:
parent
a262e4b342
commit
aca6625af4
2 changed files with 10 additions and 13 deletions
|
@ -103,21 +103,16 @@ namespace Files
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ConstrainedFileStream::ConstrainedFileStream(const char *filename, size_t start, size_t length)
|
ConstrainedFileStream::ConstrainedFileStream(std::unique_ptr<std::streambuf> buf)
|
||||||
: std::istream(new ConstrainedFileStreamBuf(filename, start, length))
|
: std::istream(buf.get())
|
||||||
|
, mBuf(std::move(buf))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstrainedFileStream::~ConstrainedFileStream()
|
|
||||||
{
|
|
||||||
delete rdbuf();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
IStreamPtr openConstrainedFileStream(const char *filename,
|
IStreamPtr openConstrainedFileStream(const char *filename,
|
||||||
size_t start, size_t length)
|
size_t start, size_t length)
|
||||||
{
|
{
|
||||||
return IStreamPtr(new ConstrainedFileStream(filename, start, length));
|
auto buf = std::unique_ptr<std::streambuf>(new ConstrainedFileStreamBuf(filename, start, length));
|
||||||
|
return IStreamPtr(new ConstrainedFileStream(std::move(buf)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,11 @@ namespace Files
|
||||||
class ConstrainedFileStream : public std::istream
|
class ConstrainedFileStream : public std::istream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConstrainedFileStream(const char *filename,
|
ConstrainedFileStream(std::unique_ptr<std::streambuf> buf);
|
||||||
size_t start=0, size_t length=0xFFFFFFFF);
|
virtual ~ConstrainedFileStream() {};
|
||||||
virtual ~ConstrainedFileStream();
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<std::streambuf> mBuf;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<std::istream> IStreamPtr;
|
typedef std::shared_ptr<std::istream> IStreamPtr;
|
||||||
|
|
Loading…
Reference in a new issue