include/common/memory.h
Memory management definitions..
- Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
+ Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
* is written in the beginning of the memory area, so
* there's no need for any carrier cell. This implies
* that each memory area is at least as big as one
- * pointer.
+ * pointer. Just like with the libc's free(), nothing
+ * is done if <ptr> is NULL.
*/
#define pool_free2(pool, ptr) \
({ \
- *(void **)ptr = (void *)pool->free_list; \
- pool->free_list = (void *)ptr; \
- pool->used--; \
+ if (likely((ptr) != NULL)) { \
+ *(void **)ptr = (void *)pool->free_list;\
+ pool->free_list = (void *)ptr; \
+ pool->used--; \
+ } \
})
/* Error unrolling */
out_fail_rep:
- if (s->req)
- pool_free2(pool2_buffer, s->req);
+ pool_free2(pool2_buffer, s->req);
out_fail_req:
- if (txn->hdr_idx.v != NULL)
- pool_free2(p->hdr_idx_pool, txn->hdr_idx.v);
+ pool_free2(p->hdr_idx_pool, txn->hdr_idx.v);
out_fail_idx:
- if (txn->rsp.cap != NULL)
- pool_free2(p->rsp_cap_pool, txn->rsp.cap);
+ pool_free2(p->rsp_cap_pool, txn->rsp.cap);
out_fail_rspcap:
- if (txn->req.cap != NULL)
- pool_free2(p->req_cap_pool, txn->req.cap);
+ pool_free2(p->req_cap_pool, txn->req.cap);
out_fail_reqcap:
out_free_task:
pool_free2(pool2_task, t);
sess_change_server(s, NULL);
}
- if (s->req)
- pool_free2(pool2_buffer, s->req);
- if (s->rep)
- pool_free2(pool2_buffer, s->rep);
+ pool_free2(pool2_buffer, s->req);
+ pool_free2(pool2_buffer, s->rep);
if (fe) {
- if (txn->hdr_idx.v != NULL)
- pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v);
+ pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v);
if (txn->rsp.cap != NULL) {
struct cap_hdr *h;
- for (h = fe->rsp_cap; h; h = h->next) {
- if (txn->rsp.cap[h->index] != NULL)
- pool_free2(h->pool, txn->rsp.cap[h->index]);
- }
+ for (h = fe->rsp_cap; h; h = h->next)
+ pool_free2(h->pool, txn->rsp.cap[h->index]);
pool_free2(fe->rsp_cap_pool, txn->rsp.cap);
}
if (txn->req.cap != NULL) {
struct cap_hdr *h;
- for (h = fe->req_cap; h; h = h->next) {
- if (txn->req.cap[h->index] != NULL)
- pool_free2(h->pool, txn->req.cap[h->index]);
- }
+ for (h = fe->req_cap; h; h = h->next)
+ pool_free2(h->pool, txn->req.cap[h->index]);
pool_free2(fe->req_cap_pool, txn->req.cap);
}
}
- if (txn->uri)
- pool_free2(pool2_requri, txn->uri);
- if (txn->cli_cookie)
- pool_free2(pool2_capture, txn->cli_cookie);
- if (txn->srv_cookie)
- pool_free2(pool2_capture, txn->srv_cookie);
-
+ pool_free2(pool2_requri, txn->uri);
+ pool_free2(pool2_capture, txn->cli_cookie);
+ pool_free2(pool2_capture, txn->srv_cookie);
pool_free2(pool2_session, s);
/* We may want to free the maximum amount of pools if the proxy is stopping */
if (fe && unlikely(fe->state == PR_STSTOPPED)) {
- if (pool2_buffer)
- pool_flush2(pool2_buffer);
- if (fe->hdr_idx_pool)
- pool_flush2(fe->hdr_idx_pool);
- if (pool2_requri)
- pool_flush2(pool2_requri);
- if (pool2_capture)
- pool_flush2(pool2_capture);
- if (pool2_session)
- pool_flush2(pool2_session);
- if (fe->req_cap_pool)
- pool_flush2(fe->req_cap_pool);
- if (fe->rsp_cap_pool)
- pool_flush2(fe->rsp_cap_pool);
+ pool_flush2(pool2_buffer);
+ pool_flush2(fe->hdr_idx_pool);
+ pool_flush2(pool2_requri);
+ pool_flush2(pool2_capture);
+ pool_flush2(pool2_session);
+ pool_flush2(fe->req_cap_pool);
+ pool_flush2(fe->rsp_cap_pool);
}
}