libc/locale: check if mmap failed before proceeding.

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Xu Xingliang 2021-12-16 11:10:33 +08:00 committed by Alan Carvalho de Assis
parent 4b2fbab998
commit f38783f4b5

View File

@ -119,7 +119,8 @@ static FAR void *momap(FAR const char *path, FAR size_t *size)
{
*size = st.st_size;
map = mmap(NULL, *size, PROT_READ, MAP_SHARED, fd, 0);
if (map[0] != MO_MAGIC && map[0] != __swap_uint32(MO_MAGIC))
if (map != MAP_FAILED &&
map[0] != MO_MAGIC && map[0] != __swap_uint32(MO_MAGIC))
{
munmap(map, *size);
map = MAP_FAILED;