1
0
Fork 0
mirror of synced 2025-03-07 03:53:26 +01:00

inetcomm: Fix memory leak on realloc failure in copy_headers_to_buf (cppcheck).

This commit is contained in:
Alex Henrie 2022-12-11 22:24:30 -07:00 committed by Alexandre Julliard
parent 02d4647c9b
commit 1afa20ae67

View file

@ -485,7 +485,7 @@ static inline propschema *impl_from_IMimePropertySchema(IMimePropertySchema *ifa
*/ */
static HRESULT copy_headers_to_buf(IStream *stm, char **ptr) 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; DWORD size = PARSER_BUF_SIZE, offset = 0, last_end = 0;
HRESULT hr; HRESULT hr;
BOOL done = FALSE; BOOL done = FALSE;
@ -497,18 +497,14 @@ static HRESULT copy_headers_to_buf(IStream *stm, char **ptr)
char *end; char *end;
DWORD read; DWORD read;
if(!buf) if(buf) size *= 2;
buf = malloc(size + 1); new_buf = realloc(buf, size + 1);
else if(!new_buf)
{
size *= 2;
buf = realloc(buf, size + 1);
}
if(!buf)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
goto fail; goto fail;
} }
buf = new_buf;
hr = IStream_Read(stm, buf + offset, size - offset, &read); hr = IStream_Read(stm, buf + offset, size - offset, &read);
if(FAILED(hr)) goto fail; if(FAILED(hr)) goto fail;