On Tue, 25 May 2021 at 21:10, Calvin Buckley <cal...@cmpct.info> wrote:

> I did some additional research and seemed to have decent luck with
> slamming a construct like this after the includes:
>
> #define emalloc  malloc
> #define erealloc realloc
> #define ecalloc  calloc
> #define estrdup  strdup
> #define estrndup strndup
> #define efree    free
>
> One could wrap it around `__clang_analyzer__` or such. Unfortunately, this
> is kinda ugly; it emits compiler warnings, but I suspect this probably
> belongs in PHP itself or perhaps in some kind of clang-analyzer addon that
> handles the e* allocation functions as well as things like mismatching them.
>

Isn't this handled by the GCC 11?

The existing malloc
> <https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Common-Function-Attributes.html#index-malloc-function-attribute>
> attribute has been extended so that it can be used to identify
> allocator/deallocator API pairs. A pair of new -Wmismatched-dealloc
> <https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Warning-Options.html#index-Wmismatched-dealloc>
> and -Wmismatched-new-delete
> <https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wmismatched-new-delete>
> warnings will complain about mismatched calls, and -Wfree-nonheap-object
> <https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Warning-Options.html#index-Wfree-nonheap-object>
> about deallocation calls with pointers not obtained from allocation
> functions. Additionally, the static analyzer will use these attributes when
> checking for leaks, double-frees, use-after-frees, and similar issues.
>
From: https://gcc.gnu.org/gcc-11/changes.html

Best regards,

George P. Banyard

Reply via email to