WebPlatformForEmbedded / libwpe

General-purpose library specifically developed for the WPE-flavored port of WebKit.
BSD 2-Clause "Simplified" License
49 stars 36 forks source link

Wrap memory allocation functions to abort on failure #114

Closed aperezdc closed 2 years ago

aperezdc commented 2 years ago

Be consistent in handling memory allocation failures by always aborting execution. Previously, some call sites for malloc/calloc/realloc tried to handle allocation failures, but some others did not. Given that WebKit's FastMalloc will itself abort on allocation failures, doing the same in libwpe keeps behaviour consistent.

A new alloc-private.h header redefines the libc functions with wpe_ prefixes, which perform checks after invoking the libc versions, and use a common wpe_alloc_fail(). The actual implementation is done through macros in order to pass along __FILE__/__LINE__ to a set of inline functions defined directly in the header, in order to help out debug failures. As a bonus, GCC's poison pragma (supported by Clang, too) prevents accidental usage of the libc allocation functions.

As a side effect, simplify the call sites which attempted to handle failures, which now can assume that allocations never fail.


Fixes #112