ref: 5dce0ef74ac7e938c82ca7d0721b7e560edd905a
parent: daaaefa7e75d056ab4c1b3b2b68fa29885e750fe
parent: 6d39b0302d38e83185ece000bc4237cd798740ca
author: Simon Howard <fraggle@soulsphere.org>
date: Sun Apr 19 08:50:34 EDT 2020
Merge pull request #1156 from devnexen/file_posix_api_upd 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);
}