Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json_object_put: Assertion `jso->_ref_count > 0' failed #747

Closed
CaledoniaProject opened this issue Feb 25, 2022 · 1 comment
Closed

json_object_put: Assertion `jso->_ref_count > 0' failed #747

CaledoniaProject opened this issue Feb 25, 2022 · 1 comment

Comments

@CaledoniaProject
Copy link

Describe the bug
Trying to call put on all the json_object I've created, but fails with assertion error

Steps To Reproduce

According to the document I should call put on all objects, but it crashes:

struct json_object *obj_root, *obj_status;
obj_root = json_tokener_parse(input);
if (obj_root == NULL)
{
	return NULL;
}

obj_status = json_object_object_get(obj_root, "Status");
if (obj_status == NULL)
{
	return NULL;
}

json_object_put(obj_status);
json_object_put(obj_root);     // crashes here

Version and Platform

  • json-c version: 0.13.1
  • OS: Ubuntu 20.04
@hawicz
Copy link
Member

hawicz commented Feb 27, 2022

You're freeing obj_status twice, first explicitly, then again as part of freeing obj_root. json_object_object_get() does not change reference counts on the object it returns so you must not free that separately from its containing object.

@hawicz hawicz closed this as completed Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants