From 5799b118b174e5ccb4863272caa74a723a09bef8 Mon Sep 17 00:00:00 2001 From: tezc Date: Tue, 13 Apr 2021 23:10:42 +0300 Subject: [PATCH] added mmap double destroy fix for windows --- memory-map/sc_mmap.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/memory-map/sc_mmap.c b/memory-map/sc_mmap.c index ccaf762..395b1c5 100644 --- a/memory-map/sc_mmap.c +++ b/memory-map/sc_mmap.c @@ -165,16 +165,27 @@ int sc_mmap_munlock(struct sc_mmap *m, size_t offset, size_t len) int sc_mmap_term(struct sc_mmap *m) { BOOL b; + int rc = 0; + + if (m->fd == -1) { + return 0; + } _close(m->fd); b = UnmapViewOfFile(m->ptr); if (b == 0) { sc_mmap_errstr(m); - return -1; + rc = -1; } - return 0; + *m = (struct sc_mmap){ + .ptr = NULL, + .fd = -1, + .len = 0, + }; + + return rc; } #else @@ -272,7 +283,7 @@ int sc_mmap_term(struct sc_mmap *m) strncpy(m->err, strerror(errno), sizeof(m->err) - 1); } - *m = (struct sc_mmap) { + *m = (struct sc_mmap){ .ptr = NULL, .fd = -1, .len = 0,