From 3578355bd0b9816fca1245f4dc9044a3badef7a1 Mon Sep 17 00:00:00 2001 From: krangelov Date: Thu, 12 Aug 2021 14:04:35 +0200 Subject: [PATCH] fix computing the size of the mapped area --- src/runtime/c/pgf/db.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runtime/c/pgf/db.cxx b/src/runtime/c/pgf/db.cxx index deba74767..56465d3ab 100644 --- a/src/runtime/c/pgf/db.cxx +++ b/src/runtime/c/pgf/db.cxx @@ -316,7 +316,7 @@ DB::DB(const char* pathname, int flags, int mode) { DB::~DB() { if (ms != NULL) { size_t size = - ms->top + size + sizeof(size_t); + ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t); munmap(ms,size); } @@ -329,10 +329,11 @@ DB::~DB() { void DB::sync() { + malloc_state *ms = current_db->ms; 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) throw std::system_error(errno, std::generic_category()); }