emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 3eac378: Avoid segfaults in jason-serialize on MS-W


From: Eli Zaretskii
Subject: [Emacs-diffs] master 3eac378: Avoid segfaults in jason-serialize on MS-Windows
Date: Tue, 7 Aug 2018 10:29:10 -0400 (EDT)

branch: master
commit 3eac378c966cd5c7fa9c62f2abcb8a9744dea69b
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    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)
---
 src/json.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/json.c b/src/json.c
index afdd9a2..540aa63 100644
--- a/src/json.c
+++ b/src/json.c
@@ -159,7 +159,12 @@ init_json_functions (void)
    than PTRDIFF_MAX.  Such objects wouldn't play well with the rest of
    Emacs's codebase, which generally uses ptrdiff_t for sizes and
    indices.  The other functions in this file also generally assume
-   that size_t values never exceed PTRDIFF_MAX.  */
+   that size_t values never exceed PTRDIFF_MAX.
+
+   In addition, we need to use a custom allocator because on
+   MS-Windows we replace malloc/free with our own functions, see
+   w32heap.c, so we must force the library to use our allocator, or
+   else we won't be able to free storage allocated by the library.  */
 
 static void *
 json_malloc (size_t size)
@@ -605,7 +610,7 @@ usage: (json-serialize OBJECT &rest ARGS)  */)
   char *string = json_dumps (json, JSON_COMPACT);
   if (string == NULL)
     json_out_of_memory ();
-  record_unwind_protect_ptr (free, string);
+  record_unwind_protect_ptr (json_free, string);
 
   return unbind_to (count, json_build_string (string));
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]