Commit bc3919abc716088cf7c33bc08d48ee2bc434c398

Edward Thomson 2020-07-11T12:14:26

global init: check error message buffer allocation Ensure that we can allocate the error message buffer. In keeping with our typical policiess, we allow (small) memory leaks in the case where we're out of memory.

diff --git a/src/global.c b/src/global.c
index 8b16166..f67811a 100644
--- a/src/global.c
+++ b/src/global.c
@@ -203,7 +203,8 @@ git_global_st *git__global_state(void)
 	if (!ptr)
 		return NULL;
 
-	git_buf_init(&ptr->error_buf, 0);
+	if (git_buf_init(&ptr->error_buf, 0) < 0)
+		return NULL;
 
 	FlsSetValue(_fls_index, ptr);
 	return ptr;
@@ -289,7 +290,9 @@ git_global_st *git__global_state(void)
 	if (!ptr)
 		return NULL;
 
-	git_buf_init(&ptr->error_buf, 0);
+	if (git_buf_init(&ptr->error_buf, 0) < 0)
+		return NULL;
+
 	pthread_setspecific(_tls_key, ptr);
 	return ptr;
 }