]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Issue #934: Also set _userdata=NULL in _json_object_maybe_free() so json_object_put...
authorEric Hawicz <erh+git@nimenees.com>
Sat, 4 Jul 2026 15:38:15 +0000 (11:38 -0400)
committerEric Hawicz <erh+git@nimenees.com>
Sat, 4 Jul 2026 15:39:02 +0000 (11:39 -0400)
Update the test_deep_nesting test output.

json_object.c
tests/test_deep_nesting.expected

index 71cd25b2a6a9d510156856a5aa9ae1c967a08436..095b84e2b4ab5c0e49b0071d1a84c665fdacaf44 100644 (file)
@@ -304,6 +304,8 @@ static inline int _json_object_put_maybe_free(struct json_object *jso, int free_
        if (jso->_user_delete)
                jso->_user_delete(jso, jso->_userdata);
        jso->_user_delete = NULL;
+       jso->_userdata = NULL; // aka _delete_parent, but json_object_put() will
+                              // have already grabbed it if it needs it.
 
        switch (jso->o_type)
        {
@@ -435,10 +437,11 @@ int json_object_put(struct json_object *jso)
 
                // All slots are cleared, now pop back up to the parent
                {
-                       json_object *parent = jso->_delete_parent;
-                       int rc;
                        // jso is a child that's already been detached from its parent
                        // so we need to actually free it now
+                       // Be sure to grab _delete_parent *before* freeing jso.
+                       json_object *parent = jso->_delete_parent;
+                       int rc;
                        assert(jso->_ref_count == 0);
                        jso->_ref_count++;   // We're the exclusive owner of jso, non-atomic add is ok.
                        // Note: the call must not be inside assert(), or it gets
index b869cfaabe79953555c86c33cad6b010fb04f9a3..b9c1ab98480f8da2a0ff417db5d291adb9d4ecee 100644 (file)
@@ -1,2 +1,3 @@
 Parsed depth 100000 string to json_object: yes
 Freed json_object
+in user_delete, userdata_val=1