1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| void ngx_destroy_pool(ngx_pool_t *pool) { ngx_pool_t *p, *n; ngx_pool_large_t *l; ngx_pool_cleanup_t *c;
// 处理cleanup链上的数据,通过handler进行处理释放 for (c = pool->cleanup; c; c = c->next) { if (c->handler) { ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "run cleanup: %p", c); c->handler(c->data); } }
#if (NGX_DEBUG)
/* * we could allocate the pool->log from this pool * so we cannot use this log while free()ing the pool */ // 打印large链上的节点和地址 for (l = pool->large; l; l = l->next) { ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc); }
// 打印内存池节点的地址和内存大小 for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p, unused: %uz", p, p->d.end - p->d.last);
if (n == NULL) { break; } }
#endif
// 释放large链上的大内存 for (l = pool->large; l; l = l->next) { if (l->alloc) { ngx_free(l->alloc); } }
// 释放pool链 for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { ngx_free(p);
if (n == NULL) { break; } } }
|