Have you tried using valgrind and static analysis?
Code:
valgrind --tool=memcheck --track-origins=yes ./alloc
==9754== Conditional jump or move depends on uninitialised value(s)
==9754== at 0x4D00397: mmap (in /usr/lib64/libc-2.29.so)
==9754== by 0x4014FA: alloc_std_page (alloc.c:113)
==9754== by 0x40180E: alloc_foo_page (alloc.c:177)
==9754== by 0x401FD9: main (alloc.c:322)
==9754== Uninitialised value was created by a heap allocation
==9754== at 0x483880B: malloc (vg_replace_malloc.c:309)
==9754== by 0x4012F6: alloc_std_data (alloc.c:51)
==9754== by 0x4013EC: alloc_std_list (alloc.c:78)
==9754== by 0x40177A: alloc_foo_page (alloc.c:164)
==9754== by 0x401FD9: main (alloc.c:322)
==9754==
==9754== Syscall param mmap(start) contains uninitialised byte(s)
==9754== at 0x4D003A6: mmap (in /usr/lib64/libc-2.29.so)
==9754== by 0x4014FA: alloc_std_page (alloc.c:113)
==9754== by 0x40180E: alloc_foo_page (alloc.c:177)
==9754== by 0x401FD9: main (alloc.c:322)
==9754== Uninitialised value was created by a heap allocation
==9754== at 0x483880B: malloc (vg_replace_malloc.c:309)
==9754== by 0x4012F6: alloc_std_data (alloc.c:51)
==9754== by 0x4013EC: alloc_std_list (alloc.c:78)
==9754== by 0x40177A: alloc_foo_page (alloc.c:164)
==9754== by 0x401FD9: main (alloc.c:322)
==9754==
Lots of messages from clang, but these are the ones that stood out, to me, as being potentially problematic
Code:
alloc.c:223:14: Semantic Issue: warning: variable 'spot' may be uninitialized when used here
alloc.c:232:28: Semantic Issue: warning: variable 'page' may be uninitialized when used here
alloc.c:272:20: Semantic Issue: warning: cast from 'uchar *' (aka 'unsigned char *') to 'std_spot *' (aka 'struct spot *') increases required alignment from 1 to 8
alloc.c:287:25: Semantic Issue: warning: cast from 'uchar *' (aka 'unsigned char *') to 'std_spot *' (aka 'struct spot *') increases required alignment from 1 to 8