aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libutil/mem_pool.c35
-rw-r--r--src/libutil/mem_pool.h10
2 files changed, 32 insertions, 13 deletions
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c
index 5e4d1fe1a..f2272fa7c 100644
--- a/src/libutil/mem_pool.c
+++ b/src/libutil/mem_pool.c
@@ -441,6 +441,27 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
const gchar *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
+
+void
+rspamd_mempool_notify_alloc_ (rspamd_mempool_t *pool, gsize size, const gchar *loc)
+{
+ GHashTable *debug_tbl = *(GHashTable **)(((guchar *)pool + sizeof (*pool)));
+ gpointer ptr;
+
+ if (G_UNLIKELY (pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
+ ptr = g_hash_table_lookup (debug_tbl, loc);
+
+ if (ptr) {
+ ptr = GSIZE_TO_POINTER (GPOINTER_TO_SIZE (ptr) + size);
+ }
+ else {
+ ptr = GSIZE_TO_POINTER (size);
+ }
+
+ g_hash_table_insert (debug_tbl, (gpointer) loc, ptr);
+ }
+}
+
static void *
memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
enum rspamd_mempool_chain_type pool_type, const gchar *loc)
@@ -454,19 +475,7 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
pool->priv->used_memory += size;
if (G_UNLIKELY (pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
- GHashTable *debug_tbl = *(GHashTable **)(((guchar *)pool + sizeof (*pool)));
- gpointer ptr;
-
- ptr = g_hash_table_lookup (debug_tbl, loc);
-
- if (ptr) {
- ptr = GSIZE_TO_POINTER (GPOINTER_TO_SIZE (ptr) + size);
- }
- else {
- ptr = GSIZE_TO_POINTER (size);
- }
-
- g_hash_table_insert (debug_tbl, (gpointer)loc, ptr);
+ rspamd_mempool_notify_alloc_ (pool, size, loc);
}
if (always_malloc && pool_type != RSPAMD_MEMPOOL_SHARED) {
diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h
index 773be33d3..1554edbd2 100644
--- a/src/libutil/mem_pool.h
+++ b/src/libutil/mem_pool.h
@@ -155,6 +155,16 @@ RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR
rspamd_mempool_alloc_((pool), (size), G_STRLOC)
/**
+ * Notify external memory usage for memory pool
+ * @param pool
+ * @param size
+ * @param loc
+ */
+void rspamd_mempool_notify_alloc_ (rspamd_mempool_t *pool, gsize size, const gchar *loc);
+#define rspamd_mempool_notify_alloc(pool, size) \
+ rspamd_mempool_notify_alloc_((pool), (size), G_STRLOC)
+
+/**
* Get memory and set it to zero
* @param pool memory pool object
* @param size bytes to allocate