]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: prepare functions to override malloc/free in pools
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Nov 2017 09:50:54 +0000 (10:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 22 Nov 2017 18:27:44 +0000 (19:27 +0100)
This will be useful to add some debugging capabilities. For now it
changes nothing.

include/common/memory.h
src/memory.c

index a5c0ec49ef794a7f9c43de70426babce738c1c03..9277ab6f41930b1b2e564e84aad5810887aeb1e3 100644 (file)
@@ -155,6 +155,23 @@ static inline void *pool_alloc_dirty(struct pool_head *pool)
        return p;
 }
 
+/* allocates an area of size <size> and returns it. The semantics are similar
+ * to those of malloc().
+ */
+static inline void *pool_alloc_area(size_t size)
+{
+       return malloc(size);
+}
+
+/* frees an area <area> of size <size> allocated by pool_alloc_area(). The
+ * semantics are identical to free() except that the size is specified and
+ * may be ignored.
+ */
+static inline void pool_free_area(void *area, size_t __maybe_unused size)
+{
+       free(area);
+}
+
 /*
  * Returns a pointer to type <type> taken from the pool <pool_type> or
  * dynamically allocated. In the first case, <pool_type> is updated to point to
index b0b32e7a746a66c646edef86265793714cfc04e5..fc1f62483d5f464fc7b886b802fc416813faae56 100644 (file)
@@ -117,7 +117,7 @@ void *__pool_refill_alloc(struct pool_head *pool, unsigned int avail)
                if (pool->limit && pool->allocated >= pool->limit)
                        return NULL;
 
-               ptr = malloc(pool->size + POOL_EXTRA);
+               ptr = pool_alloc_area(pool->size + POOL_EXTRA);
                if (!ptr) {
                        pool->failed++;
                        if (failed)
@@ -163,7 +163,7 @@ void pool_flush2(struct pool_head *pool)
                temp = next;
                next = *POOL_LINK(pool, temp);
                pool->allocated--;
-               free(temp);
+               pool_free_area(temp, pool->size + POOL_EXTRA);
        }
        pool->free_list = next;
        HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock);
@@ -199,7 +199,7 @@ void pool_gc2(struct pool_head *pool_ctx)
                        temp = next;
                        next = *POOL_LINK(entry, temp);
                        entry->allocated--;
-                       free(temp);
+                       pool_free_area(temp, entry->size + POOL_EXTRA);
                }
                entry->free_list = next;
                if (entry != pool_ctx)