fix computing the size of the mapped area

This commit is contained in:
krangelov
2021-08-12 14:04:35 +02:00
parent 39f38ed0e2
commit 3578355bd0

View File

@@ -316,7 +316,7 @@ DB::DB(const char* pathname, int flags, int mode) {
DB::~DB() { DB::~DB() {
if (ms != NULL) { if (ms != NULL) {
size_t size = size_t size =
ms->top + size + sizeof(size_t); ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t);
munmap(ms,size); munmap(ms,size);
} }
@@ -329,10 +329,11 @@ DB::~DB() {
void DB::sync() void DB::sync()
{ {
malloc_state *ms = current_db->ms;
size_t size = size_t size =
current_db->ms->top + size + sizeof(size_t); ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t);
int res = msync((void *) current_db->ms, size, MS_SYNC | MS_INVALIDATE); int res = msync((void *) ms, size, MS_SYNC | MS_INVALIDATE);
if (res != 0) if (res != 0)
throw std::system_error(errno, std::generic_category()); throw std::system_error(errno, std::generic_category());
} }