From 02a05eea4e6ba41811f130b322660bea8918e1a0 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 12 Apr 2017 20:47:59 +0200 Subject: [PATCH] cJSON: Add cJSON_malloc and cJSON_free --- cJSON.c | 10 ++++++++++ cJSON.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/cJSON.c b/cJSON.c index bc343ba..a25556d 100644 --- a/cJSON.c +++ b/cJSON.c @@ -2585,3 +2585,13 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons return false; } } + +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} + +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); +} diff --git a/cJSON.h b/cJSON.h index c29ba17..0ddab6f 100644 --- a/cJSON.h +++ b/cJSON.h @@ -241,6 +241,10 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); /* Macro for iterating over an array */ #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ +CJSON_PUBLIC(void *) cJSON_malloc(size_t size); +CJSON_PUBLIC(void) cJSON_free(void *object); + #ifdef __cplusplus } #endif