Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-02-01 23:54:42 +0400
committerRussell Belfer <arrbee@arrbee.com>2012-02-01 23:54:42 +0400
commit62a1f713de384e141045facf3c1a53d9642e8eb5 (patch)
tree1e4369d4d97256cff259552f0bc442342c6cdda6 /src/attr.c
parent4ea79a9d6e8f52faf8598b96ed53c3066cba0f83 (diff)
Fix memory leak in attr file cache
Actually look for the file by the same cache key that we store it under. Rocket science!
Diffstat (limited to 'src/attr.c')
-rw-r--r--src/attr.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/attr.c b/src/attr.c
index 3fc01e8c9..ddcc3dcf0 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -222,8 +222,9 @@ int git_attr_cache__push_file(
int error = GIT_SUCCESS;
git_attr_cache *cache = &repo->attrcache;
git_buf path = GIT_BUF_INIT;
- git_attr_file *file;
+ git_attr_file *file = NULL;
int add_to_cache = 0;
+ const char *cache_key;
if (base != NULL) {
if ((error = git_buf_joinpath(&path, base, filename)) < GIT_SUCCESS)
@@ -232,10 +233,18 @@ int git_attr_cache__push_file(
}
/* either get attr_file from cache or read from disk */
- file = git_hashtable_lookup(cache->files, filename);
+ cache_key = filename;
+ if (repo && git__prefixcmp(cache_key, git_repository_workdir(repo)) == 0)
+ cache_key += strlen(git_repository_workdir(repo));
+
+ file = git_hashtable_lookup(cache->files, cache_key);
if (file == NULL && git_path_exists(filename) == GIT_SUCCESS) {
- if ((error = git_attr_file__new(&file)) == GIT_SUCCESS)
- error = loader(repo, filename, file);
+ if ((error = git_attr_file__new(&file)) == GIT_SUCCESS) {
+ if ((error = loader(repo, filename, file)) < GIT_SUCCESS) {
+ git_attr_file__free(file);
+ file = NULL;
+ }
+ }
add_to_cache = (error == GIT_SUCCESS);
}