Rainier:
On Mon, Nov 9, 2020 at 6:07 PM Ranier Vilela <ranier.vf@gmail.com> wrote:
> Em seg., 9 de nov. de 2020 às 13:54, Francisco Olarte <folarte@peoplecall.com> escreveu:
...
>> you try malloc or any other function and do not program it right. This
>> is C memory management 101.
>
> Like this:
> l_alloc function (lauxlib.c)
> 995: return realloc(ptr, nsize);
Did you bother reading the docs? Specifically the phrase "When nsize
is not zero, the allocator must behave like realloc. " ( btw, that
usage is, IIRC, protected inside the else branch of a nice "if
(nsize==0)".
If you want to look for ptr leaks you have to search for the usages of
the l_alloc function passed and stored inside the state. I believe
they are confined inside lmem.* but i'm not sure of that one.
Realloc only is secure like this:
(void)ud; (void)osize; /* not used */
if (nsize == 0) {
free(ptr);
return NULL;
}
else
{
void * newptr;
newptr = realloc(ptr, nsize);
if (newptr == NULL)
return ptr;
return newptr;
}
Ranier Vilela