mirror of https://github.com/aria2/aria2
fix memory leak when exception thrown
parent
faa6955c8d
commit
1e48d35f3b
|
@ -347,8 +347,13 @@ void Piece::updateWrCache(WrDiskCache* diskCache, unsigned char* data,
|
|||
cell->len = len;
|
||||
cell->capacity = capacity;
|
||||
bool rv;
|
||||
rv = wrCache_->cacheData(cell);
|
||||
assert(rv);
|
||||
try {
|
||||
rv = wrCache_->cacheData(cell);
|
||||
assert(rv);
|
||||
} catch (RecoverableException& e) {
|
||||
delete cell;
|
||||
throw;
|
||||
}
|
||||
rv = diskCache->update(wrCache_.get(), len);
|
||||
assert(rv);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "Segment.h"
|
||||
#include "WrDiskCache.h"
|
||||
#include "Piece.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -81,8 +82,13 @@ ssize_t SinkStreamFilter::transform(const std::shared_ptr<BinaryStream>& out,
|
|||
size_t capacity = std::max(len, static_cast<size_t>(4_k));
|
||||
auto dataCopy = new unsigned char[capacity];
|
||||
memcpy(dataCopy, inbuf + alen, len);
|
||||
piece->updateWrCache(wrDiskCache_, dataCopy, 0, len, capacity,
|
||||
segment->getPositionToWrite() + alen);
|
||||
try {
|
||||
piece->updateWrCache(wrDiskCache_, dataCopy, 0, len, capacity,
|
||||
segment->getPositionToWrite() + alen);
|
||||
} catch (RecoverableException& e) {
|
||||
delete[] dataCopy;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue