From 61ade8b943ecad8a082a0696377721c2ed879d86 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Wed, 15 Jul 2020 13:55:20 +0000 Subject: [PATCH] zone: Fix backed file alloc for BSD. Check for -1 in addition to NULL on mmap data (David CARLIER) https://gitlab.com/xonotic/darkplaces/-/merge_requests/55 git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12815 d7cf8633-e32d-0410-b094-e92efae38249 --- zone.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zone.c b/zone.c index 69d053d8..e2ec8ca7 100644 --- a/zone.c +++ b/zone.c @@ -107,6 +107,9 @@ void Mem_PrintList(size_t minallocationsize); #if FILE_BACKED_MALLOC #include #include +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif typedef struct mmap_data_s { size_t len; @@ -127,7 +130,7 @@ static void *mmap_malloc(size_t size) data = (unsigned char *) mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0); close(fd); unlink(vabuf); - if(!data) + if(!data || data == (void *)-1) return NULL; data->len = size; return (void *) (data + 1); -- 2.39.2