ngx_array.c allocation question

Valentin V. Bartenev vbart at nginx.com
Tue Oct 27 21:42:11 UTC 2015


On Tuesday 27 October 2015 20:52:43 Joel Cunningham wrote:
> Hi,
> 
> I'm fairly new to the NGINX sources and have been studying ngx_array.c (from 
1.9.5), particularly how the array grows when full.
> 
> I'm having some confusion about how pool memory isn't leaked when the new 
array size can not fit within the current pool allocation and we call 
ngx_palloc().  The new allocation is assigned to the local variable new, which 
is eventually assigned to a->elts, but the old memory that was claimed out of 
the previous pool allocation (and tracked by a->elts) isn't released/marked as 
no longer used in the pool.  I would have expected some manipulation of p-
>d.last, similarly to how ngx_array_destroy() releases the memory from the 
pool allocation.  Is there something I'm not understanding about the way array 
uses the memory pool?
> 
> It seems like over time an array that continues to grow (past the current 
pool allocation) would leave memory claimed within the pool allocation that 
it's no longer using or tracking
> 

It's ok, since pools usually have relatively short lives.

  wbr, Valentin V. Bartenev



More information about the nginx-devel mailing list