psxmem: fix map retry breakage
authornotaz <notasas@gmail.com>
Tue, 1 Oct 2024 16:36:25 +0000 (19:36 +0300)
committernotaz <notasas@gmail.com>
Mon, 7 Oct 2024 22:37:19 +0000 (01:37 +0300)
fixes 417b59ebc326fc753f8c881c24fc7aff975df7ea

libpcsxcore/psxmem.c

index a70cc62..a8dfaa8 100644 (file)
@@ -90,10 +90,12 @@ void *psxMap(unsigned long addr, size_t size, int is_fixed,
                enum psxMapTag tag)
 {
        int try_, can_retry_addr = 0;
-       void *ret;
+       void *ret = MAP_FAILED;
 
        for (try_ = 0; try_ < 3; try_++)
        {
+               if (ret != MAP_FAILED)
+                       psxUnmap(ret, size, tag);
                ret = psxMapHook(addr, size, tag, &can_retry_addr);
                if (ret == NULL)
                        return MAP_FAILED;
@@ -109,8 +111,6 @@ void *psxMap(unsigned long addr, size_t size, int is_fixed,
                        if (can_retry_addr && ((addr ^ (uintptr_t)ret) & ~0xff000000l)) {
                                unsigned long mask;
 
-                               psxUnmap(ret, size, tag);
-
                                // try to use similarly aligned memory instead
                                // (recompiler prefers this)
                                mask = try_ ? 0xffff : 0xffffff;