Skip to content

Commit

Permalink
COMMON: Use ScopedArray in ReadStream::readStream()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Oct 29, 2016
1 parent 9d19aa4 commit a31a737
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/common/readstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "src/common/readstream.h"
#include "src/common/memreadstream.h"
#include "src/common/error.h"
#include "src/common/scopedptr.h"

namespace Common {

Expand All @@ -62,19 +63,12 @@ ReadStream::~ReadStream() {
}

MemoryReadStream *ReadStream::readStream(size_t dataSize) {
byte *buf = new byte[dataSize];
ScopedArray<byte> buf(new byte[dataSize]);

try {
if (read(buf.get(), dataSize) != dataSize)
throw Exception(kReadError);

if (read(buf, dataSize) != dataSize)
throw Exception(kReadError);

} catch (...) {
delete[] buf;
throw;
}

return new MemoryReadStream(buf, dataSize, true);
return new MemoryReadStream(buf.release(), dataSize, true);
}


Expand Down

0 comments on commit a31a737

Please sign in to comment.