]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
zone: Fix backed file alloc for BSD. Check for -1 in addition to NULL on mmap data...
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Jul 2020 13:55:20 +0000 (13:55 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Jul 2020 13:55:20 +0000 (13:55 +0000)
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

diff --git a/zone.c b/zone.c
index 69d053d853df662b7da939629890e418bafe634b..e2ec8ca75d5560a62d018c563f3aa8945a8bab7f 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -107,6 +107,9 @@ void Mem_PrintList(size_t minallocationsize);
 #if FILE_BACKED_MALLOC
 #include <stdlib.h>
 #include <sys/mman.h>
+#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);