X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Flookups%2Fjson.c;h=15b8617512f07d666d8ac918345089b3f66af0a5;hb=c4639661040515feaa187921d47580b767f7c3b1;hp=5fe1f1c5d5a90770f6d25eb6a4ffd7f5a631e6d9;hpb=9669c6e06fa8441557a70ba0759eda19287681ad;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/lookups/json.c b/src/src/lookups/json.c index 5fe1f1c5d..15b861751 100644 --- a/src/src/lookups/json.c +++ b/src/src/lookups/json.c @@ -11,6 +11,28 @@ +/* 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). + +Assume that the file is trusted, so no tainting */ + +static void * +json_malloc(size_t nbytes) +{ +void * p = store_get((int)nbytes, FALSE); +/* 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 +42,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); @@ -85,7 +110,7 @@ for (int k = 1; (key = string_nextinlist(&keystring, &sep, NULL, 0)); k++) : json_object_get(j, CCS key) ) ) { - DEBUG(D_lookup) debug_printf("%s, for key %d: '%s'\n", + DEBUG(D_lookup) debug_printf_indent("%s, for key %d: '%s'\n", numeric ? US"bad index, or not json array" : US"no such key, or not json object",