Fix bug that numOpenFile_ is not reduced when MultiDiskAdaptor is deleted

This bug caused assertion error in RequestGroupMan::ensureMaxOpenFileLimit
This commit is contained in:
Tatsuhiro Tsujikawa 2013-12-31 22:57:11 +09:00
parent 3802c8dc2c
commit 8216bdba79
3 changed files with 18 additions and 2 deletions

View File

@ -124,7 +124,10 @@ MultiDiskAdaptor::MultiDiskAdaptor()
readOnly_{false}
{}
MultiDiskAdaptor::~MultiDiskAdaptor() {}
MultiDiskAdaptor::~MultiDiskAdaptor()
{
closeFile();
}
namespace {
std::unique_ptr<DiskWriterEntry> createDiskWriterEntry
@ -267,10 +270,15 @@ void MultiDiskAdaptor::openExistingFile()
void MultiDiskAdaptor::closeFile()
{
size_t n = 0;
openedDiskWriterEntries_.clear();
for(auto& dwent : diskWriterEntries_) {
dwent->closeFile();
if(dwent->isOpen()) {
++n;
dwent->closeFile();
}
}
getRequestGroupMan()->reduceNumOfOpenedFile(n);
}
namespace {

View File

@ -985,4 +985,10 @@ void RequestGroupMan::ensureMaxOpenFileLimit(size_t numNewFile)
numOpenFile_ += numNewFile - numClose;
}
void RequestGroupMan::reduceNumOfOpenedFile(size_t numCloseFile)
{
assert(numOpenFile_ >= numCloseFile);
numOpenFile_ -= numCloseFile;
}
} // namespace aria2

View File

@ -357,6 +357,8 @@ public:
// Currently the only download using MultiDiskAdaptor is affected by
// the global limit.
void ensureMaxOpenFileLimit(size_t numNewFile);
// Reduces the number of open files managed by this object.
void reduceNumOfOpenedFile(size_t numCloseFile);
};
} // namespace aria2