Module: wine Branch: master Commit: 1afa20ae679d7ee4587f19b1cc22b1a9525decd9 URL: https://gitlab.winehq.org/wine/wine/-/commit/1afa20ae679d7ee4587f19b1cc22b1a...
Author: Alex Henrie alexhenrie24@gmail.com Date: Sun Dec 11 22:24:30 2022 -0700
inetcomm: Fix memory leak on realloc failure in copy_headers_to_buf (cppcheck).
---
dlls/inetcomm/mimeole.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/dlls/inetcomm/mimeole.c b/dlls/inetcomm/mimeole.c index 232e09aa075..dd2c00b01fa 100644 --- a/dlls/inetcomm/mimeole.c +++ b/dlls/inetcomm/mimeole.c @@ -485,7 +485,7 @@ static inline propschema *impl_from_IMimePropertySchema(IMimePropertySchema *ifa */ static HRESULT copy_headers_to_buf(IStream *stm, char **ptr) { - char *buf = NULL; + char *buf = NULL, *new_buf; DWORD size = PARSER_BUF_SIZE, offset = 0, last_end = 0; HRESULT hr; BOOL done = FALSE; @@ -497,18 +497,14 @@ static HRESULT copy_headers_to_buf(IStream *stm, char **ptr) char *end; DWORD read;
- if(!buf) - buf = malloc(size + 1); - else - { - size *= 2; - buf = realloc(buf, size + 1); - } - if(!buf) + if(buf) size *= 2; + new_buf = realloc(buf, size + 1); + if(!new_buf) { hr = E_OUTOFMEMORY; goto fail; } + buf = new_buf;
hr = IStream_Read(stm, buf + offset, size - offset, &read); if(FAILED(hr)) goto fail;