summaryrefslogtreecommitdiff
path: root/src/attr.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-01-11 21:07:16 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-01-11 23:21:46 -0800
commit1dbcc9fc4e6f5264d5bb46f6d7f744eb4a4063e4 (patch)
treec6ab4917dcb9814569e8c2a7423c0034996c9f9a /src/attr.c
parent0cfcff5daac50d5a4ba41d5125b108cdfceed832 (diff)
downloadlibgit2-1dbcc9fc4e6f5264d5bb46f6d7f744eb4a4063e4.tar.gz
Fix several memory issues
This contains fixes for several issues discovered by MSVC and by valgrind, including some bad data access, some memory leakage (in where certain files were not being successfully added to the cache), and some code simplification.
Diffstat (limited to 'src/attr.c')
-rw-r--r--src/attr.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/attr.c b/src/attr.c
index 06a6601b4..cbc2a5bf5 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -227,14 +227,16 @@ int git_attr_cache__push_file(
git_attr_file *file;
int add_to_cache = 0;
- if (base != NULL &&
- (error = git_buf_joinpath(&path, base, filename)) < GIT_SUCCESS)
- goto cleanup;
+ if (base != NULL) {
+ if ((error = git_buf_joinpath(&path, base, filename)) < GIT_SUCCESS)
+ goto cleanup;
+ filename = path.ptr;
+ }
/* either get attr_file from cache or read from disk */
- file = git_hashtable_lookup(cache->files, path.ptr);
- if (file == NULL && git_futils_exists(path.ptr) == GIT_SUCCESS) {
- error = (*loader)(repo, path.ptr, &file);
+ file = git_hashtable_lookup(cache->files, filename);
+ if (file == NULL && git_futils_exists(filename) == GIT_SUCCESS) {
+ error = (*loader)(repo, filename, &file);
add_to_cache = (error == GIT_SUCCESS);
}