From f1ecb9fac867de00b3c0d7d36f205fb4a1a811cd Mon Sep 17 00:00:00 2001 From: "Gregory J. Ward" Date: Thu, 31 Oct 2024 23:55:04 +0000 Subject: [PATCH] feat: Allow creation of empty shared map to be resized later --- src/rt/RdataShareMap.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/rt/RdataShareMap.cpp b/src/rt/RdataShareMap.cpp index d120aaf4..b0b6f4fd 100644 --- a/src/rt/RdataShareMap.cpp +++ b/src/rt/RdataShareMap.cpp @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: RdataShareMap.cpp,v 2.2 2024/10/30 01:38:21 greg Exp $"; +static const char RCSid[] = "$Id: RdataShareMap.cpp,v 2.3 2024/10/31 23:55:04 greg Exp $"; #endif /* * RdataShareMap.cpp @@ -80,7 +80,7 @@ RdataShareMap::RdataShareMap(const char *name, int flags, size_t siz) return; } } - mmorg = (void *)mmap(NULL, siz, mmprot, + if (siz) mmorg = (void *)mmap(NULL, siz, mmprot, MAP_SHARED|(name ? MAP_FILE : MAP_ANON), fd, 0); close(fd); if (mmorg == MAP_FAILED) { @@ -107,8 +107,6 @@ RdataShareMap::~RdataShareMap() size_t RdataShareMap::Resize(size_t new_siz) { - if (!mmorg) - return 0; if (new_siz > 0) { if (new_siz == osiz) return osiz; @@ -155,7 +153,7 @@ RdataShareMap::Resize(size_t new_siz) close(fd); return 0; } - munmap(mmorg, osiz); + if (mmorg) munmap(mmorg, osiz); mmorg = mmap(NULL, new_siz, mode&RDSread ? PROT_READ|PROT_WRITE : PROT_WRITE, MAP_SHARED|MAP_FILE, fd, 0);