Skip to content

Commit 36f8074

Browse files
committed
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.
1 parent e7873eb commit 36f8074

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/odb_loose.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,11 +1028,16 @@ static int loose_backend__readstream(
10281028

10291029
done:
10301030
if (error < 0) {
1031-
git_futils_mmap_free(&stream->map);
1032-
git_zstream_free(&stream->zstream);
1033-
git_hash_ctx_cleanup(hash_ctx);
1034-
git__free(hash_ctx);
1035-
git__free(stream);
1031+
if(stream && stream->map.data)
1032+
git_futils_mmap_free(&stream->map);
1033+
if(stream)
1034+
git_zstream_free(&stream->zstream);
1035+
if(stream)
1036+
git__free(stream);
1037+
if(hash_ctx) {
1038+
git_hash_ctx_cleanup(hash_ctx);
1039+
git__free(hash_ctx);
1040+
}
10361041
}
10371042

10381043
git_buf_dispose(&object_path);

0 commit comments

Comments
 (0)