Page MenuHome

fixes for potential crashes in guard alloc stats
Needs RevisionPublic

Authored by James Fulop (Yam) on Sun, Jan 12, 9:14 AM.

Details

Summary

This fixes a potential crash if we call MEM_guarded_printmemlist_stats before any allocations have occurred. (repro'd locally)
This fixes a potential nullptr deref if the CRTs malloc returns null.

This caught my attention after looking at static analysis warnings generated by Visual Studio 2019. Here are the warnings that are fixed with this.

Warning C6386 Buffer overrun while writing to 'printblock': the writable size is 'sizeof(MemPrintBlock)*totblock' bytes, but '24' bytes might be written. bf_intern_guardedalloc D:\PROJECTS\BLENDER\SOURCE\INTERN\GUARDEDALLOC\INTERN\MALLOCN_GUARDED_IMPL.C 787
Warning C6387 'printblock' could be '0': this does not adhere to the specification for the function 'qsort'. bf_intern_guardedalloc D:\PROJECTS\BLENDER\SOURCE\INTERN\GUARDEDALLOC\INTERN\MALLOCN_GUARDED_IMPL.C 787
Warning C6011 Dereferencing NULL pointer 'pb'. See line 787 for an earlier location where this can occur bf_intern_guardedalloc D:\PROJECTS\BLENDER\SOURCE\INTERN\GUARDEDALLOC\INTERN\MALLOCN_GUARDED_IMPL.C 793

Diff Detail

Repository
rB Blender

Event Timeline

Brecht Van Lommel (brecht) requested changes to this revision.Mon, Jan 27, 5:35 PM

It should still print if totblock == 0, so I'd rather have some NULL pointer checks for qsort() and free() to avoid this warning.

This revision now requires changes to proceed.Mon, Jan 27, 5:35 PM