Commit da8138b01217824cf211fa491608a7b067cf8e43

Edward Thomson 2018-12-06T12:59:17

Merge pull request #4906 from QBobWatson/bugfix Fix segfault in loose_backend__readstream

diff --git a/src/odb_loose.c b/src/odb_loose.c
index 3c0ed67..12607dd 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -1028,11 +1028,15 @@ 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) {
+			git_futils_mmap_free(&stream->map);
+			git_zstream_free(&stream->zstream);
+			git__free(stream);
+		}
+		if (hash_ctx) {
+			git_hash_ctx_cleanup(hash_ctx);
+			git__free(hash_ctx);
+		}
 	}
 
 	git_buf_dispose(&object_path);