OPTIM/MINOR: move the hdr_idx pools out of the proxy struct

It makes no sense to have one pointer to the hdr_idx pool in each proxy
struct since these pools do not depend on the proxy. Let's have a common
pool instead as it is already the case for other types.
diff --git a/include/proto/hdr_idx.h b/include/proto/hdr_idx.h
index 9e67a00..3de4361 100644
--- a/include/proto/hdr_idx.h
+++ b/include/proto/hdr_idx.h
@@ -1,23 +1,23 @@
 /*
-  include/proto/hdr_idx.h
-  This file defines function prototypes for fast header indexation.
-
-  Copyright (C) 2000-2006 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
-  License as published by the Free Software Foundation, version 2.1
-  exclusively.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
+ * include/proto/hdr_idx.h
+ * This file defines function prototypes for fast header indexation.
+ *
+ * Copyright (C) 2000-2011 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
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 
 #ifndef _PROTO_HDR_IDX_H
 #define _PROTO_HDR_IDX_H
@@ -25,6 +25,8 @@
 #include <common/config.h>
 #include <types/hdr_idx.h>
 
+extern struct pool_head *pool2_hdr_idx;
+
 /*
  * Initialize the list pointers.
  * list->size must already be set. If list->size is set and list->v is
diff --git a/include/types/proxy.h b/include/types/proxy.h
index 46e03a1..2abd213 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -296,7 +296,6 @@
 	struct cap_hdr *rsp_cap;		/* chained list of response headers to be captured */
 	struct pool_head *req_cap_pool,		/* pools of pre-allocated char ** used to build the sessions */
 	                 *rsp_cap_pool;
-	struct pool_head *hdr_idx_pool;         /* pools of pre-allocated int* used for headers indexing */
 	struct list req_add, rsp_add;           /* headers to be added */
 	struct pxcounters be_counters;		/* backend statistics counters */
 	struct pxcounters fe_counters;		/* frontend statistics counters */
diff --git a/src/cfgparse.c b/src/cfgparse.c
index ed64457..dac6bca 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -44,6 +44,7 @@
 #include <proto/checks.h>
 #include <proto/dumpstats.h>
 #include <proto/frontend.h>
+#include <proto/hdr_idx.h>
 #include <proto/lb_chash.h>
 #include <proto/lb_fwlc.h>
 #include <proto/lb_fwrr.h>
@@ -5991,10 +5992,6 @@
 							     curproxy->nb_rsp_cap * sizeof(char *),
 							     MEM_F_SHARED);
 
-		curproxy->hdr_idx_pool = create_pool("hdr_idx",
-						     MAX_HTTP_HDR * sizeof(struct hdr_idx_elem),
-						     MEM_F_SHARED);
-
 		/* first, we will invert the servers list order */
 		newsrv = NULL;
 		while (curproxy->srv) {
@@ -6598,6 +6595,10 @@
 		}
 	}
 
+	pool2_hdr_idx = create_pool("hdr_idx",
+				    MAX_HTTP_HDR * sizeof(struct hdr_idx_elem),
+				    MEM_F_SHARED);
+
 	if (cfgerr > 0)
 		err_code |= ERR_ALERT | ERR_FATAL;
  out:
diff --git a/src/frontend.c b/src/frontend.c
index 548cd02..195a424 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -136,7 +136,7 @@
 		 */
 		s->txn.hdr_idx.size = MAX_HTTP_HDR;
 
-		if (unlikely((s->txn.hdr_idx.v = pool_alloc2(s->fe->hdr_idx_pool)) == NULL))
+		if (unlikely((s->txn.hdr_idx.v = pool_alloc2(pool2_hdr_idx)) == NULL))
 			goto out_free_rspcap; /* no memory */
 
 		/* and now initialize the HTTP transaction state */
diff --git a/src/haproxy.c b/src/haproxy.c
index f54fc8e..cd8df66 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -76,6 +76,7 @@
 #include <proto/buffers.h>
 #include <proto/checks.h>
 #include <proto/fd.h>
+#include <proto/hdr_idx.h>
 #include <proto/log.h>
 #include <proto/protocols.h>
 #include <proto/proto_http.h>
@@ -953,7 +954,6 @@
 
 		pool_destroy2(p->req_cap_pool);
 		pool_destroy2(p->rsp_cap_pool);
-		pool_destroy2(p->hdr_idx_pool);
 		pool_destroy2(p->table.pool);
 
 		p0 = p;
@@ -1003,6 +1003,7 @@
 	pool_destroy2(pool2_appsess);
 	pool_destroy2(pool2_pendconn);
 	pool_destroy2(pool2_sig_handlers);
+	pool_destroy2(pool2_hdr_idx);
     
 	if (have_appsession) {
 		pool_destroy2(apools.serverid);
diff --git a/src/hdr_idx.c b/src/hdr_idx.c
index a8c595d..13f9b55 100644
--- a/src/hdr_idx.c
+++ b/src/hdr_idx.c
@@ -1,7 +1,7 @@
 /*
  * Header indexation functions.
  *
- * Copyright 2000-2008 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -11,8 +11,10 @@
  */
 
 #include <common/config.h>
+#include <common/memory.h>
 #include <proto/hdr_idx.h>
 
+struct pool_head *pool2_hdr_idx = NULL;
 
 /*
  * Add a header entry to <list> after element <after>. <after> is ignored when
diff --git a/src/proxy.c b/src/proxy.c
index 14e37eb..d274dfe 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -813,7 +813,7 @@
 	 * a struct hdr_idx for it if we did not have one.
 	 */
 	if (unlikely(!s->txn.hdr_idx.v && (be->acl_requires & ACL_USE_L7_ANY))) {
-		if ((s->txn.hdr_idx.v = pool_alloc2(s->fe->hdr_idx_pool)) == NULL)
+		if ((s->txn.hdr_idx.v = pool_alloc2(pool2_hdr_idx)) == NULL)
 			return 0; /* not enough memory */
 
 		/* and now initialize the HTTP transaction state */
diff --git a/src/session.c b/src/session.c
index 9c66906..dbef9ee 100644
--- a/src/session.c
+++ b/src/session.c
@@ -372,8 +372,8 @@
 		s->store[i].ts = NULL;
 	}
 
+	pool_free2(pool2_hdr_idx, txn->hdr_idx.v);
 	if (fe) {
-		pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v);
 		pool_free2(fe->rsp_cap_pool, txn->rsp.cap);
 		pool_free2(fe->req_cap_pool, txn->req.cap);
 	}
@@ -397,7 +397,7 @@
 	/* We may want to free the maximum amount of pools if the proxy is stopping */
 	if (fe && unlikely(fe->state == PR_STSTOPPED)) {
 		pool_flush2(pool2_buffer);
-		pool_flush2(fe->hdr_idx_pool);
+		pool_flush2(pool2_hdr_idx);
 		pool_flush2(pool2_requri);
 		pool_flush2(pool2_capture);
 		pool_flush2(pool2_session);