Novum / vkQuake

Vulkan Quake port based on QuakeSpasm
GNU General Public License v2.0
1.81k stars 220 forks source link

NULL-dereferencing after a failed allocation #645

Closed fmwviormv closed 1 year ago

fmwviormv commented 1 year ago

When I build vkquake in DEBUG=1, it shows a lot of warnings after run:

mimalloc: warning: unable to allocate aligned OS memory directly, fall back to over-allocation (67108864 bytes, address: 0x1229d46000, alignment: 67108864, commit: 1)

And then stopped by a NULL pointer dereferencing after a failed allocation:

* thread #1, stop reason = signal SIGSEGV
    frame #0: 0x0000000e02132608 vkquake`CreateTaskQueue(capacity=256) at tasks.c:178:23
   175          assert (capacity > 0);
   176          assert ((capacity & (capacity - 1)) == 0); // Needs to be power of 2
   177          task_queue_t *queue = Mem_Alloc (sizeof (task_queue_t) + (sizeof (atomic_uint32_t) * (capacity - 1)));
-> 178          queue->capacity_mask = capacity - 1;
                                     ^
   179          queue->push_semaphore = SDL_CreateSemaphore (capacity - 1);
   180          queue->pop_semaphore = SDL_CreateSemaphore (0);
   181          return queue;
(lldb) print queue
(task_queue_t *) $0 = NULL

But after I used -DUSE_CRT_MALLOC to build flags, I don't see that problem. Isn't the game old enough to work fast enough without those complex memory management codes? Some operating systems (say OpenBSD) have strong memory allocation mechanism which could be helpful for finding allocation bugs, but with a non-standard memory allocation it couldn't help.

Novum commented 1 year ago

This seems like a bug with mimalloc interacting with OpenBSD. OpenBSD isn't really a tested target, so not sure how to proceed. I could disable mimalloc on anything but Windows/macOS and Linux because only those are known good.

Novum commented 1 year ago

cab11a4b4bff1237225e8e5264ea6c1dac319d94