Subject: Re: [RFC PATCH v3 2/3] grep: make PCRE2 aware of custom allocator

From: Junio C Hamano <[email-masked]>
Date: Wed, 07 Aug 2019 11:15:36 -0700

Carlo Arenas <[email-masked]> writes:

>> > +#ifdef USE_NED_ALLOCATOR
>> > +static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
>> > +{
>> > +     return malloc(size);
>>
>> Should this be xmalloc() to get consistent out-of-memory handling?
>
> good point, note though that since it is inside a USE_NED_ALLOCATOR
> ifdef it is really
> nedalloc in disguise

It would be nedalloc() wrapped inside the "die if we cannot
allocate, possibly after releasing resources held in various caches"
xmalloc() wrapper.  So (1) either xmalloc or malloc would end up
eventually calling nedalloc that can be freed with nedfree, so from
that point of view either can be used without upsetting "free()",
and (2) we should use xmalloc() here because we care about
consistent OOM behaviour throughout the system.

Thanks.