wtfbbqhax / tremulous

:godmode: Modern modular idTech3 based engine, Tremulous

Home Page:http://wtfbbqhax.github.io/tremulous/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Renderer allocates 'zero sized' hunk chunks

wtfbbqhax opened this issue · comments

GeneratePermanentShader allocates zero sized chunks via Hunk_Alloc. This may be benign but it probably is not.

First it updates state

        Hunk_SwapBanks();

The size of the allocated block will be different depending on HUNK_DEBUG

#ifdef HUNK_DEBUG
    size += sizeof(hunkblock_t);
#endif

    // round to cacheline
    size = (size+31)&~31;

With HUNK_DEBUG enabled size += 0 -> size = 64
Without size=0

It may cause a problem in release, or it may cause a problem in Debug builds which is not clear. Pointers are often tested on truthiness alone, rather than knowing the size of the allocation.

image

I added a counter to this and found it happens quite a lot, from startup loading ui main menu

p count_zero_sized_allocs
(int) $0 = 558

Adding a early return null and the menu is still loaded, no issue, but it actually resulted in more memory allocation in most cases. The only values that decreased are "low tempHighwater", "high permanent" and "total hunks in use".

high tempHighwater is more than 2x the original

image

Interesting behavior