aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2018-08-07 17:28:35 +0300
committerEli Zaretskii2018-08-07 17:28:35 +0300
commit3eac378c966cd5c7fa9c62f2abcb8a9744dea69b (patch)
treefe842cd85fb8deded1f0d260cf467629d3626996
parent5f32ba5015b5c17dbbe0453e8fe3efc343fe8489 (diff)
downloademacs-3eac378c966cd5c7fa9c62f2abcb8a9744dea69b.tar.gz
emacs-3eac378c966cd5c7fa9c62f2abcb8a9744dea69b.zip
Avoid segfaults in jason-serialize on MS-Windows
* src/json.c (Fjson_serialize): Free the string with 'json_free', not 'free', since it was allocated with 'json_malloc'. (Bug#32381)
-rw-r--r--src/json.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/json.c b/src/json.c
index afdd9a25481..540aa630c59 100644
--- a/src/json.c
+++ b/src/json.c
@@ -159,7 +159,12 @@ init_json_functions (void)
159 than PTRDIFF_MAX. Such objects wouldn't play well with the rest of 159 than PTRDIFF_MAX. Such objects wouldn't play well with the rest of
160 Emacs's codebase, which generally uses ptrdiff_t for sizes and 160 Emacs's codebase, which generally uses ptrdiff_t for sizes and
161 indices. The other functions in this file also generally assume 161 indices. The other functions in this file also generally assume
162 that size_t values never exceed PTRDIFF_MAX. */ 162 that size_t values never exceed PTRDIFF_MAX.
163
164 In addition, we need to use a custom allocator because on
165 MS-Windows we replace malloc/free with our own functions, see
166 w32heap.c, so we must force the library to use our allocator, or
167 else we won't be able to free storage allocated by the library. */
163 168
164static void * 169static void *
165json_malloc (size_t size) 170json_malloc (size_t size)
@@ -605,7 +610,7 @@ usage: (json-serialize OBJECT &rest ARGS) */)
605 char *string = json_dumps (json, JSON_COMPACT); 610 char *string = json_dumps (json, JSON_COMPACT);
606 if (string == NULL) 611 if (string == NULL)
607 json_out_of_memory (); 612 json_out_of_memory ();
608 record_unwind_protect_ptr (free, string); 613 record_unwind_protect_ptr (json_free, string);
609 614
610 return unbind_to (count, json_build_string (string)); 615 return unbind_to (count, json_build_string (string));
611} 616}