Commit 3e8a17b0 by Patrick Steinhardt

buffer: fix memory leak if unable to grow buffer

If growing a buffer fails, we set its pointer to the static
`git_buf__oom` structure. While we correctly free the old pointer if
`git__malloc` returned an error, we do not free it if there was an
integer overflow while calculating the new allocation size. Fix this
issue by freeing the pointer to plug the memory leak.
parent 68cfb580
......@@ -70,8 +70,11 @@ int git_buf_try_grow(
new_size = (new_size + 7) & ~7;
if (new_size < buf->size) {
if (mark_oom)
if (mark_oom) {
if (buf->ptr && buf->ptr != git_buf__initbuf)
git__free(buf->ptr);
buf->ptr = git_buf__oom;
}
git_error_set_oom();
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment