[MEDIUM] memory: update pool_free2() to support NULL pointers

In order to make pool usage more convenient, let pool_free2()
support NULL pointers by doing nothing, just like the standard
free(3) call does.

The various call places have been updated to remove the now
useless checks.
This commit is contained in:
Willy Tarreau 2008-08-03 17:41:33 +02:00
parent a534fea478
commit 48d63db7a8
4 changed files with 30 additions and 53 deletions

View File

@ -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 <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--; \
} \
})

View File

@ -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 )

View File

@ -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);

View File

@ -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);
}
}