auto file unmap

This commit is contained in:
Xiao YiFang 2022-06-16 20:34:32 +08:00
parent 947323854a
commit 2da252539a
2 changed files with 8 additions and 3 deletions

View file

@ -5,6 +5,7 @@
#include <zlib.h>
#include <string.h>
#include <QDataStream>
#include <QScopeGuard>
namespace ChunkedStorage {
@ -144,7 +145,6 @@ char * Reader::getBlock( uint32_t address, vector< char > & chunk )
uint32_t uncompressedSize;
uint32_t compressedSize;
// = file.read< uint32_t >();
in >> uncompressedSize >> compressedSize;
@ -155,17 +155,20 @@ char * Reader::getBlock( uint32_t address, vector< char > & chunk )
auto chunkDataBytes = file.map( offsets[ chunkIdx ] + 8, compressedSize );
// file.read( &compressedData.front(), compressedData.size() );
auto autoUnmap = qScopeGuard(
[ & ] {
file.unmap( chunkDataBytes );
} );
Q_UNUSED( autoUnmap )
unsigned long decompressedLength = chunk.size();
if( uncompress( (unsigned char *)&chunk.front(), &decompressedLength, chunkDataBytes, compressedSize ) != Z_OK
|| decompressedLength != chunk.size() )
{
file.unmap( chunkDataBytes );
throw exFailedToDecompressChunk();
}
file.unmap( chunkDataBytes );
}
size_t offsetInChunk = address & 0xffFF;

View file

@ -19,6 +19,8 @@
#include "wildcard.hh"
#include <QtConcurrent>
#include "base/globalregex.hh"
#include <QFutureSynchronizer>
#include <QSemaphoreReleaser>
using std::vector;
using std::string;