Use array_ptr to remove try block

pull/34/head
Tatsuhiro Tsujikawa 2012-11-15 22:05:59 +09:00
parent 6b2f5ab1f5
commit 9c1fe4addd
1 changed files with 6 additions and 8 deletions

View File

@ -56,6 +56,7 @@
#include "fmt.h" #include "fmt.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "PeerStorage.h" #include "PeerStorage.h"
#include "array_fun.h"
namespace aria2 { namespace aria2 {
@ -205,16 +206,13 @@ void BtPieceMessage::send()
void BtPieceMessage::pushPieceData(int64_t offset, int32_t length) const void BtPieceMessage::pushPieceData(int64_t offset, int32_t length) const
{ {
assert(length <= 16*1024); assert(length <= 16*1024);
unsigned char* buf = new unsigned char[length]; array_ptr<unsigned char> buf(new unsigned char[length]);
ssize_t r; ssize_t r;
try { r = getPieceStorage()->getDiskAdaptor()->readData(buf, length, offset);
r = getPieceStorage()->getDiskAdaptor()->readData(buf, length, offset);
} catch(RecoverableException& e) {
delete [] buf;
throw;
}
if(r == length) { if(r == length) {
getPeerConnection()->pushBytes(buf, length); unsigned char* dbuf = buf;
buf.reset(0);
getPeerConnection()->pushBytes(dbuf, length);
} else { } else {
throw DL_ABORT_EX(EX_DATA_READ); throw DL_ABORT_EX(EX_DATA_READ);
} }