From: cloudwalk Date: Wed, 15 Jul 2020 13:55:20 +0000 (+0000) Subject: zone: Fix backed file alloc for BSD. Check for -1 in addition to NULL on mmap data... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=61ade8b943ecad8a082a0696377721c2ed879d86;p=xonotic%2Fdarkplaces.git 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 --- 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);