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

Memory Returned by json_object_to_json_string not freed #316

Closed
vaasu1234 opened this issue Apr 24, 2017 · 1 comment
Closed

Memory Returned by json_object_to_json_string not freed #316

vaasu1234 opened this issue Apr 24, 2017 · 1 comment

Comments

@vaasu1234
Copy link

const char * json_str = json_object_to_json_string(jsonobj);
json_object_put(jsonobj);
printf("%s\n", json_str);
json_object_object_add(jsonobj, "key", json_object_new_int64(value)); //

I can still print the string even after freeing the object (line 3)?

To check if obj is really freed, I tried adding an object and i'm hitting seg fault which proved object is freed. So, why json_str is still valid after object freed?

@vaasu1234
Copy link
Author

Looks like a side-effect of free. free(ptr) doesn't necessarily erase memory. So the contents of the memory might still be valid until the block is reassigned.

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

1 participant