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->len = len;
|
||||||
cell->capacity = capacity;
|
cell->capacity = capacity;
|
||||||
bool rv;
|
bool rv;
|
||||||
|
try {
|
||||||
rv = wrCache_->cacheData(cell);
|
rv = wrCache_->cacheData(cell);
|
||||||
assert(rv);
|
assert(rv);
|
||||||
|
} catch (RecoverableException& e) {
|
||||||
|
delete cell;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
rv = diskCache->update(wrCache_.get(), len);
|
rv = diskCache->update(wrCache_.get(), len);
|
||||||
assert(rv);
|
assert(rv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "WrDiskCache.h"
|
#include "WrDiskCache.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
|
#include "DlAbortEx.h"
|
||||||
|
|
||||||
namespace aria2 {
|
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));
|
size_t capacity = std::max(len, static_cast<size_t>(4_k));
|
||||||
auto dataCopy = new unsigned char[capacity];
|
auto dataCopy = new unsigned char[capacity];
|
||||||
memcpy(dataCopy, inbuf + alen, len);
|
memcpy(dataCopy, inbuf + alen, len);
|
||||||
|
try {
|
||||||
piece->updateWrCache(wrDiskCache_, dataCopy, 0, len, capacity,
|
piece->updateWrCache(wrDiskCache_, dataCopy, 0, len, capacity,
|
||||||
segment->getPositionToWrite() + alen);
|
segment->getPositionToWrite() + alen);
|
||||||
|
} catch (RecoverableException& e) {
|
||||||
|
delete[] dataCopy;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue