Module: wine Branch: master Commit: a6f3e4ad222cd78eee20639c2c7b8f7315c13070 URL: https://gitlab.winehq.org/wine/wine/-/commit/a6f3e4ad222cd78eee20639c2c7b8f7...
Author: Alex Henrie alexhenrie24@gmail.com Date: Mon Feb 6 22:26:56 2023 -0700
winhlp32: Fix memory leak on realloc failure in HLPFILE_RtfAddBitmap (cppcheck).
---
programs/winhlp32/hlpfile.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/programs/winhlp32/hlpfile.c b/programs/winhlp32/hlpfile.c index e8ae723cff0..4fb6853cfe6 100644 --- a/programs/winhlp32/hlpfile.c +++ b/programs/winhlp32/hlpfile.c @@ -966,6 +966,7 @@ static BOOL HLPFILE_RtfAddBitmap(struct RtfData* rd, HLPFILE* file, const BYTE* const BYTE* pict_beg; BYTE* alloc = NULL; BITMAPINFO* bi; + BITMAPINFO* new_bi; ULONG off, csz; unsigned nc = 0; BOOL clrImportant = FALSE; @@ -1013,8 +1014,13 @@ static BOOL HLPFILE_RtfAddBitmap(struct RtfData* rd, HLPFILE* file, const BYTE* if (!nc && bi->bmiHeader.biBitCount <= 8) nc = 1 << bi->bmiHeader.biBitCount;
- bi = realloc(bi, sizeof(*bi) + nc * sizeof(RGBQUAD)); - if (!bi) return FALSE; + new_bi = realloc(bi, sizeof(*bi) + nc * sizeof(RGBQUAD)); + if (!new_bi) + { + free(bi); + return FALSE; + } + bi = new_bi; for (i = 0; i < nc; i++) { bi->bmiColors[i].rgbBlue = ptr[0];