]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] memory: update pool_free2() to support NULL pointers
authorWilly Tarreau <w@1wt.eu>
Sun, 3 Aug 2008 15:41:33 +0000 (17:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 3 Aug 2008 18:48:50 +0000 (20:48 +0200)
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.

include/common/memory.h
src/appsession.c
src/client.c
src/session.c

index 835d79df08efbe5ee765d7a3a2816db70bb5f790..765351ce2c2099dcc07dd381564dcea362c3cc9d 100644 (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--;                           \
+        }                                               \
 })
 
 
index b3f2c76a4937a7dd20553adf3ee6fe69ceb9224e..45050b55139fa5ea0b052af4e451e6c58c7b4885 100644 (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 )
index 502ee979605d95ebda27b6642a91951a862fec0b..a4d52652b45dbc759836df71bc1e72db06fa4bf2 100644 (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);
index c27ef75790b1f0ba0b265cc1747d0c8e3ccbeb40..ceef0b7dfe7edc99c2afc6b0c161f43f0a6a2a7d 100644 (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);
        }
 }