Eina_File: Avoid using munmap() on file->global_map.
authorGuilherme Iscaro <iscaro@profusion.mobi>
Wed, 2 Aug 2017 19:37:10 +0000 (16:37 -0300)
committerCedric BAIL <cedric@osg.samsung.com>
Wed, 2 Aug 2017 23:03:20 +0000 (16:03 -0700)
When a virtualized file is created the file->global_map will not
point to a mmapped region, thus it's not safe to use munmap() during
the file cleanup. Only use munmap() if the file is backed by a FD.

Fixes: T5234.
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/lib/eina/eina_file.c
src/lib/eina/eina_file_win32.c

index 2fae7b7..7e154db 100644 (file)
@@ -295,10 +295,12 @@ eina_file_real_close(Eina_File *file)
         free(map);
      }
 
-   if (!file->copied && file->global_map != MAP_FAILED)
-     munmap(file->global_map, file->length);
-
-   if (file->fd != -1) close(file->fd);
+   if (file->fd != -1)
+     {
+        if (file->global_map != MAP_FAILED)
+          munmap(file->global_map, file->length);
+        close(file->fd);
+     }
 }
 
 static void
index 9a5b6fd..3a5831e 100644 (file)
@@ -383,11 +383,12 @@ eina_file_real_close(Eina_File *file)
         free(map);
      }
 
-   if (file->global_map != MAP_FAILED)
-     UnmapViewOfFile(file->global_map);
-
    if (file->handle != INVALID_HANDLE_VALUE)
-     CloseHandle(file->handle);
+     {
+        if (file->global_map != MAP_FAILED)
+          UnmapViewOfFile(file->global_map);
+        CloseHandle(file->handle);
+     }
 }
 
 static void