summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Rabinoff <jrabinoff6@math.gatech.edu>2018-12-04 10:12:24 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2019-01-18 23:01:37 +0000
commit822095446026ba0105fbce6ed0d32338bf46ec58 (patch)
treea06c318e3ca6b93195b67da895d37f59c501c4f8
parentc3b2053d964bea36b5a9440321b5d02ae13e3421 (diff)
downloadlibgit2-822095446026ba0105fbce6ed0d32338bf46ec58.tar.gz
Fix segfault in loose_backend__readstream
If the routine exits with error before stream or hash_ctx is initialized, the program will segfault when trying to free them.
-rw-r--r--src/odb_loose.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 470421e15..92238571a 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -1028,11 +1028,16 @@ static int loose_backend__readstream(
done:
if (error < 0) {
- git_futils_mmap_free(&stream->map);
- git_zstream_free(&stream->zstream);
- git_hash_ctx_cleanup(hash_ctx);
- git__free(hash_ctx);
- git__free(stream);
+ if(stream && stream->map.data)
+ git_futils_mmap_free(&stream->map);
+ if(stream)
+ git_zstream_free(&stream->zstream);
+ if(stream)
+ git__free(stream);
+ if(hash_ctx) {
+ git_hash_ctx_cleanup(hash_ctx);
+ git__free(hash_ctx);
+ }
}
git_buf_free(&object_path);