diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-09-21 15:18:42 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-09-21 15:20:28 +0200 |
| commit | 3e8a17b01b30a5aca5e10ef6f02635111315724e (patch) | |
| tree | 58bd3471f75521c4fbdb65ea0a89c0a9ae4025fa /src/buffer.c | |
| parent | 68cfb580e19c419992ba0b0a299e5fd6dc60ed99 (diff) | |
| download | libgit2-3e8a17b01b30a5aca5e10ef6f02635111315724e.tar.gz | |
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.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/buffer.c b/src/buffer.c index 51fb48a45..8acf2accd 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -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; |
