Skip to content

Commit f4770e4

Browse files
Douglas Swansonethomson
authored andcommitted
Fix Issue libgit2#4047 Check return codes and free objects
1 parent 668fa07 commit f4770e4

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

examples/general.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ static void config_files(const char *repo_path, git_repository* repo)
724724
int32_t autocorrect;
725725
git_config *cfg;
726726
git_config *snap_cfg;
727+
int error_code;
727728

728729
printf("\n*Config Listing*\n");
729730

@@ -740,9 +741,33 @@ static void config_files(const char *repo_path, git_repository* repo)
740741
git_config_get_string(&email, snap_cfg, "user.email");
741742
printf("Email: %s\n", email);
742743

743-
/**
744-
* Remember to free the configurations after usage.
745-
*/
744+
error_code = git_config_get_int32(&autocorrect, cfg, "help.autocorrect");
745+
switch (error_code)
746+
{
747+
case 0:
748+
printf("Autocorrect: %d\n", autocorrect);
749+
break;
750+
case GIT_ENOTFOUND:
751+
printf("Autocorrect: Undefined\n");
752+
break;
753+
default:
754+
check_error(error_code, "get_int32 failed");
755+
}
746756
git_config_free(cfg);
757+
758+
check_error(git_repository_config_snapshot(&snap_cfg, repo), "config snapshot");
759+
error_code = git_config_get_string(&email, snap_cfg, "user.email");
760+
switch (error_code)
761+
{
762+
case 0:
763+
printf("Email: %s\n", email);
764+
break;
765+
case GIT_ENOTFOUND:
766+
printf("Email: Undefined\n");
767+
break;
768+
default:
769+
check_error(error_code, "get_string failed");
770+
}
771+
747772
git_config_free(snap_cfg);
748773
}

0 commit comments

Comments
 (0)