Skip to content

Commit

Permalink
Use json_decref() properly in tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
akheron committed Mar 9, 2013
1 parent a1882fe commit 3d0d61f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/github_commits.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ int main(int argc, char *argv[])
if(!json_is_array(root))
{
fprintf(stderr, "error: root is not an array\n");
json_decref(root);
return 1;
}

Expand All @@ -140,6 +141,7 @@ int main(int argc, char *argv[])
if(!json_is_object(data))
{
fprintf(stderr, "error: commit data %d is not an object\n", i + 1);
json_decref(root);
return 1;
}

Expand All @@ -154,13 +156,15 @@ int main(int argc, char *argv[])
if(!json_is_object(commit))
{
fprintf(stderr, "error: commit %d: commit is not an object\n", i + 1);
json_decref(root);
return 1;
}

message = json_object_get(commit, "message");
if(!json_is_string(message))
{
fprintf(stderr, "error: commit %d: message is not a string\n", i + 1);
json_decref(root);
return 1;
}

Expand Down
5 changes: 5 additions & 0 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ We check that the returned value really is an array::
if(!json_is_array(root))
{
fprintf(stderr, "error: root is not an array\n");
json_decref(root);
return 1;
}

Expand All @@ -192,6 +193,7 @@ Then we proceed to loop over all the commits in the array::
if(!json_is_object(data))
{
fprintf(stderr, "error: commit data %d is not an object\n", i + 1);
json_decref(root);
return 1;
}
...
Expand All @@ -209,20 +211,23 @@ object. We also do proper type checks::
if(!json_is_string(sha))
{
fprintf(stderr, "error: commit %d: sha is not a string\n", i + 1);
json_decref(root);
return 1;
}

commit = json_object_get(data, "commit");
if(!json_is_object(commit))
{
fprintf(stderr, "error: commit %d: commit is not an object\n", i + 1);
json_decref(root);
return 1;
}

message = json_object_get(commit, "message");
if(!json_is_string(message))
{
fprintf(stderr, "error: commit %d: message is not a string\n", i + 1);
json_decref(root);
return 1;
}
...
Expand Down

0 comments on commit 3d0d61f

Please sign in to comment.