diff --git a/include/common/memory.h b/include/common/memory.h index 835d79df0..765351ce2 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -2,7 +2,7 @@ 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 @@ -186,13 +186,16 @@ void *pool_destroy2(struct pool_head *pool); * 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 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--; \ + } \ }) diff --git a/src/appsession.c b/src/appsession.c index b3f2c76a4..45050b551 100644 --- a/src/appsession.c +++ b/src/appsession.c @@ -148,13 +148,9 @@ int match_str(const void *key1, const void *key2) }/* end match_str */ void destroy(appsess *temp1) { - if (temp1->sessid) pool_free2(apools.sessid, temp1->sessid); - - if (temp1->serverid) pool_free2(apools.serverid, temp1->serverid); - - pool_free2(pool2_appsess, temp1); + pool_free2(pool2_appsess, temp1); } /* end destroy */ void appsession_cleanup( void ) diff --git a/src/client.c b/src/client.c index 502ee9796..a4d52652b 100644 --- a/src/client.c +++ b/src/client.c @@ -433,17 +433,13 @@ int event_accept(int fd) { /* 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); diff --git a/src/session.c b/src/session.c index c27ef7579..ceef0b7df 100644 --- a/src/session.c +++ b/src/session.c @@ -47,57 +47,39 @@ void session_free(struct session *s) 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); } }