Commit 05c24c44e67a09b88411aca5f12d31e907d1a35d

Edward Thomson 2018-02-09T18:25:46

Merge pull request #4527 from pks-t/pks/resource-leaks Plug resource leaks

diff --git a/src/hash/hash_win32.c b/src/hash/hash_win32.c
index 50c23e8..779802c 100644
--- a/src/hash/hash_win32.c
+++ b/src/hash/hash_win32.c
@@ -57,7 +57,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
 	if (hash_prov.prov.cng.open_algorithm_provider(&hash_prov.prov.cng.handle, GIT_HASH_CNG_HASH_TYPE, NULL, GIT_HASH_CNG_HASH_REUSABLE) < 0) {
 		FreeLibrary(hash_prov.prov.cng.dll);
 
-		giterr_set(GITERR_OS "algorithm provider could not be initialized");
+		giterr_set(GITERR_OS, "algorithm provider could not be initialized");
 		return -1;
 	}
 
diff --git a/src/odb.c b/src/odb.c
index 802c721..07206c1 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -1373,6 +1373,8 @@ int git_odb_open_wstream(
 	(*stream)->received_bytes = 0;
 
 done:
+	if (error)
+		git__free(ctx);
 	return error;
 }
 
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 713288d..470421e 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -433,7 +433,8 @@ static int read_header_loose(git_rawobj *out, git_buf *loc)
 	}
 
 done:
-	p_close(fd);
+	if (fd >= 0)
+		p_close(fd);
 	return error;
 }
 
@@ -1030,6 +1031,7 @@ done:
 		git_futils_mmap_free(&stream->map);
 		git_zstream_free(&stream->zstream);
 		git_hash_ctx_cleanup(hash_ctx);
+		git__free(hash_ctx);
 		git__free(stream);
 	}