ref: 6d39b0302d38e83185ece000bc4237cd798740ca
parent: 1857858144fc14ed5b370bb9a86653606c647ae6
author: David Carlier <devnexen@gmail.com>
date: Mon Apr 1 15:42:23 EDT 2019
Checking possible wrong mapping in memory and other little tweaks.
--- a/src/w_file_posix.c
+++ b/src/w_file_posix.c
@@ -60,13 +60,15 @@
protection, flags,
wad->handle, 0);
- wad->wad.mapped = result;
-
- if (result == NULL)
+ if (result == NULL || result == (void *)-1)
{fprintf(stderr, "W_POSIX_OpenFile: Unable to mmap() %s - %s\n",
filename, strerror(errno));
}
+ else
+ {+ wad->wad.mapped = result;
+ }
}
unsigned int GetFileLength(int handle)
@@ -92,6 +94,7 @@
result->wad.file_class = &posix_wad_file;
result->wad.length = GetFileLength(handle);
result->wad.path = M_StringDuplicate(path);
+ result->wad.mapped = NULL;
result->handle = handle;
// Try to map the file into memory with mmap:
@@ -110,7 +113,11 @@
// If mapped, unmap it.
// Close the file
-
+
+ if (posix_wad->wad.mapped)
+ {+ munmap(posix_wad->wad.mapped, posix_wad->wad.length);
+ }
close(posix_wad->handle);
Z_Free(posix_wad);
}
--
⑨