Skip to content

Commit 832278b

Browse files
author
Douglas Swanson
committed
Fix issue libgit2#4046 Seg fault in config_files()
1 parent 238b8cc commit 832278b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/general.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void blob_parsing(git_repository *repo);
5757
static void revwalking(git_repository *repo);
5858
static void index_walking(git_repository *repo);
5959
static void reference_listing(git_repository *repo);
60-
static void config_files(const char *repo_path);
60+
static void config_files(const char *repo_path, git_repository *repo);
6161

6262
/**
6363
* Almost all libgit2 functions return 0 on success or negative on error.
@@ -115,7 +115,7 @@ int main (int argc, char** argv)
115115
revwalking(repo);
116116
index_walking(repo);
117117
reference_listing(repo);
118-
config_files(repo_path);
118+
config_files(repo_path, repo);
119119

120120
/**
121121
* Finally, when you're done with the repository, you can free it as well.
@@ -692,12 +692,13 @@ static void reference_listing(git_repository *repo)
692692
*
693693
* [config]: http://libgit2.github.com/libgit2/#HEAD/group/config
694694
*/
695-
static void config_files(const char *repo_path)
695+
static void config_files(const char *repo_path, git_repository* repo)
696696
{
697697
const char *email;
698698
char config_path[256];
699699
int32_t j;
700700
git_config *cfg;
701+
git_config *snap_cfg;
701702

702703
printf("\n*Config Listing*\n");
703704

@@ -710,6 +711,7 @@ static void config_files(const char *repo_path)
710711
git_config_get_int32(&j, cfg, "help.autocorrect");
711712
printf("Autocorrect: %d\n", j);
712713

713-
git_config_get_string(&email, cfg, "user.email");
714+
check_error(git_repository_config_snapshot(&snap_cfg, repo), "config snapshot");
715+
git_config_get_string(&email, snap_cfg, "user.email");
714716
printf("Email: %s\n", email);
715717
}

0 commit comments

Comments
 (0)