Minor fixes for warnings and error propagation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 0f7119b..037cb3f 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -418,7 +418,11 @@ GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
* Get a snapshot of the repository's configuration
*
* Convenience function to take a snapshot from the repository's
- * configuration.
+ * configuration. The contents of this snapshot will not change,
+ * even if the underlying config files are modified.
+ *
+ * The configuration file must be freed once it's no longer
+ * being used by the user.
*
* @param out Pointer to store the loaded configuration
* @param repo the repository
diff --git a/src/config_file.c b/src/config_file.c
index c09a032..b00d082 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -247,18 +247,15 @@ static int refcounted_strmap_alloc(refcounted_strmap **out)
int error;
map = git__calloc(1, sizeof(refcounted_strmap));
- if (!map) {
- giterr_set_oom();
- return -1;
- }
+ GITERR_CHECK_ALLOC(map);
git_atomic_set(&map->refcount, 1);
- if ((error = git_strmap_alloc(&map->values)) < 0) {
+
+ if ((error = git_strmap_alloc(&map->values)) < 0)
git__free(map);
- return error;
- }
+ else
+ *out = map;
- *out = map;
return error;
}
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 28c0a6b..fc1354f 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -219,7 +219,7 @@ static int git_diff_driver_load(
git_diff_driver *drv = NULL;
size_t namelen = strlen(driver_name);
khiter_t pos;
- git_config *cfg, *repo_cfg;
+ git_config *cfg;
git_buf name = GIT_BUF_INIT;
const git_config_entry *ce;
bool found_driver = false;
diff --git a/src/repository.c b/src/repository.c
index 87f6f7a..43a4760 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -627,10 +627,11 @@ int git_repository_config(git_config **out, git_repository *repo)
int git_repository_config_snapshot(git_config **out, git_repository *repo)
{
+ int error;
git_config *weak;
- if (git_repository_config__weakptr(&weak, repo) < 0)
- return -1;
+ if ((error = git_repository_config__weakptr(&weak, repo)) < 0)
+ return error;
return git_config_snapshot(out, weak);
}