No you don't. Why this happens becomes clear if you look at the
definition of the json_is_object macro:
#define json_typeof(json) ((json)->type)
#define json_is_object(json) (json && json_typeof(json) == JSON_OBJECT)
When the macros are expanded, the if statement in parse_json()
becomes:
if ((root = json_loads(text, 0, &error)) && ((root = json_loads(text, 0, &error))->type) == JSON_OBJECT) return 1;
So json_loads() is called two times and the first result is thrown
away. Consequently, json_decref() only frees half of the memory that
is allocated.
You can confirm this by changing your code to:
int parse_json(const char *text) {
json_t *root;
json_error_t error;
root = json_loads(text, 0, &error);
if (!json_is_object(root)) return 1;
json_decref(root);
return 0;
}
This way, no memory is leaked.
Petri