[PATCH 4/5] avifil32: Don't leak the buffer on HeapReAlloc() failure in AVIFILE_AddFrame().
Henri Verbeet
hverbeet at codeweavers.com
Tue Jan 5 14:29:02 CST 2010
Perhaps the code should also just double the buffer. I can send another patch
for that if needed.
---
dlls/avifil32/avifile.c | 22 +++++++++++++---------
1 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/dlls/avifil32/avifile.c b/dlls/avifil32/avifile.c
index ea6d6b1..57ebb11 100644
--- a/dlls/avifil32/avifile.c
+++ b/dlls/avifil32/avifile.c
@@ -1383,16 +1383,20 @@ static HRESULT AVIFILE_AddFrame(IAVIStreamImpl *This, DWORD ckid, DWORD size, DW
}
if (This->idxFmtChanges == NULL || This->nIdxFmtChanges <= This->sInfo.dwFormatChangeCount) {
- This->nIdxFmtChanges += 16;
- if (This->idxFmtChanges == NULL)
- This->idxFmtChanges =
- HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->nIdxFmtChanges * sizeof(AVIINDEXENTRY));
- else
+ DWORD new_count = This->nIdxFmtChanges + 16;
+ void *new_buffer;
+
+ if (This->idxFmtChanges == NULL) {
This->idxFmtChanges =
- HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->idxFmtChanges,
- This->nIdxFmtChanges * sizeof(AVIINDEXENTRY));
- if (This->idxFmtChanges == NULL)
- return AVIERR_MEMORY;
+ HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, new_count * sizeof(AVIINDEXENTRY));
+ if (!This->idxFmtChanges) return AVIERR_MEMORY;
+ } else {
+ new_buffer = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->idxFmtChanges,
+ new_count * sizeof(AVIINDEXENTRY));
+ if (!new_buffer) return AVIERR_MEMORY;
+ This->idxFmtChanges = new_buffer;
+ }
+ This->nIdxFmtChanges = new_count;
}
This->sInfo.dwFlags |= AVISTREAMINFO_FORMATCHANGES;
--
1.6.4.4
More information about the wine-patches
mailing list