summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2019-01-10 19:17:57 +0000
committerJeremy Harris <jgh146exb@wizmail.org>2019-01-10 19:17:57 +0000
commit6db8b72c861b99114bdcb9188abfe20bc77e67d2 (patch)
tree338b4bc8058e4bb290b9c56d666943a5b8c710bd /src
parentb13354a7c428fdb2286d2227fdad5378a1ee9426 (diff)
Use project memory-management for json lookup
Diffstat (limited to 'src')
-rw-r--r--src/src/lookups/json.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/src/lookups/json.c b/src/src/lookups/json.c
index 5fe1f1c5d..0b28b731e 100644
--- a/src/src/lookups/json.c
+++ b/src/src/lookups/json.c
@@ -11,6 +11,26 @@
+/* All use of allocations will be done against the POOL_SEARCH memory,
+which is freed once by search_tidyup(). Make the free call a dummy.
+This burns some 300kB in handling a 37kB JSON file, for the benefit of
+a fast free. The alternative of staying with malloc is nearly as bad,
+eyeballing the activity there are 20% the number of free vs. alloc
+calls (before the big bunch at the end). */
+
+static void *
+json_malloc(size_t nbytes)
+{
+void * p = store_get((int)nbytes);
+/* debug_printf("%s %d: %p\n", __FUNCTION__, (int)nbytes, p); */
+return p;
+}
+static void
+json_free(void * p)
+{
+/* debug_printf("%s: %p\n", __FUNCTION__, p); */
+}
+
/*************************************************
* Open entry point *
*************************************************/
@@ -20,8 +40,11 @@
static void *
json_open(uschar *filename, uschar **errmsg)
{
-FILE *f = Ufopen(filename, "rb");
-if (f == NULL)
+FILE * f;
+
+json_set_alloc_funcs(json_malloc, json_free);
+
+if (!(f = Ufopen(filename, "rb")))
{
int save_errno = errno;
*errmsg = string_open_failed(errno, "%s for json search", filename);