lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tuesday, December 09, 2014 02:02:48 PM Santosh Kadam wrote:
> Hi, there
> Thank you for your responses...
> 
> Attaching the code, Please let me know if any issues within the calling...
> RgdsSantosh
> 
> 
> static void *custom_alloc (void *ud, void *ptr, size_t osize, size_t nsize)
> {
  ...
> return my_realloc(ptr, nsize,__FILE__,__LINE__);
> }

At a glance I see a similar problem as was mentioned a few days ago. Realloc 
will memcpy nsize which can be larger than the old block size and that's 
undefined behavior. 

Also this part:

> if (nsize == 0) {
>   totalmem -= osize;
> }

The manual states "When ptr is NULL, osize encodes the kind of object that Lua 
is allocating." You could be setting totalmem less than 0.

Again from the manual, "Lua assumes that the allocator never fails when osize 
>= nsize" which yours may. Although I'm not sure if that's relevant. You're 
not running out of memory with this tiny program.


-- 
tom <telliamed@whoopdedo.org>