From a5755b10a7b8538d504029a5ed5d5a00d7117314 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 13 Jun 2002 23:54:55 +0000 Subject: [PATCH] Authors: Mike McCormack , Jeremy White Fixed memory leaks. --- dlls/ole32/storage.c | 42 ++++++++++++++++++++++++++---------------- dlls/setupapi/queue.c | 7 +++++-- dlls/user/lstr.c | 1 + dlls/x11drv/winpos.c | 1 + graphics/path.c | 7 ++++--- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/dlls/ole32/storage.c b/dlls/ole32/storage.c index ac9c791057d..2cfc5aeef8f 100644 --- a/dlls/ole32/storage.c +++ b/dlls/ole32/storage.c @@ -885,6 +885,8 @@ HRESULT WINAPI IStream16_fnWrite( * (we just migrate newsize bytes) */ LPBYTE curdata,data = HeapAlloc(GetProcessHeap(),0,newsize+BIGSIZE); + HRESULT r = E_FAIL; + cc = newsize; blocknr = This->stde.pps_sb; curdata = data; @@ -899,31 +901,35 @@ HRESULT WINAPI IStream16_fnWrite( } /* frees complete chain for this stream */ if (!STORAGE_set_big_chain(hf,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) - return E_FAIL; + goto err; curdata = data; blocknr = This->stde.pps_sb = STORAGE_get_free_small_blocknr(hf); if (blocknr<0) - return E_FAIL; + goto err; cc = newsize; while (cc>0) { if (!STORAGE_put_small_block(hf,blocknr,curdata)) - return E_FAIL; + goto err; cc -= SMALLSIZE; if (cc<=0) { if (!STORAGE_set_small_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) - return E_FAIL; + goto err; break; } else { int newblocknr = STORAGE_get_free_small_blocknr(hf); if (newblocknr<0) - return E_FAIL; + goto err; if (!STORAGE_set_small_chain(hf,blocknr,newblocknr)) - return E_FAIL; + goto err; blocknr = newblocknr; } curdata += SMALLSIZE; } + r = S_OK; + err: HeapFree(GetProcessHeap(),0,data); + if(r != S_OK) + return r; } } This->stde.pps_size = newsize; @@ -978,47 +984,51 @@ HRESULT WINAPI IStream16_fnWrite( } else { /* Migrate small blocks to big blocks */ LPBYTE curdata,data = HeapAlloc(GetProcessHeap(),0,oldsize+BIGSIZE); + HRESULT r = E_FAIL; + cc = oldsize; blocknr = This->stde.pps_sb; curdata = data; /* slurp in */ while (cc>0) { - if (!STORAGE_get_small_block(hf,blocknr,curdata)) { - HeapFree(GetProcessHeap(),0,data); - return E_FAIL; - } + if (!STORAGE_get_small_block(hf,blocknr,curdata)) + goto err2; curdata += SMALLSIZE; cc -= SMALLSIZE; blocknr = STORAGE_get_next_small_blocknr(hf,blocknr); } /* free small block chain */ if (!STORAGE_set_small_chain(hf,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) - return E_FAIL; + goto err2; curdata = data; blocknr = This->stde.pps_sb = STORAGE_get_free_big_blocknr(hf); if (blocknr<0) - return E_FAIL; + goto err2; /* put the data into the big blocks */ cc = This->stde.pps_size; while (cc>0) { if (!STORAGE_put_big_block(hf,blocknr,curdata)) - return E_FAIL; + goto err2; cc -= BIGSIZE; if (cc<=0) { if (!STORAGE_set_big_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) - return E_FAIL; + goto err2; break; } else { int newblocknr = STORAGE_get_free_big_blocknr(hf); if (newblocknr<0) - return E_FAIL; + goto err2; if (!STORAGE_set_big_chain(hf,blocknr,newblocknr)) - return E_FAIL; + goto err2; blocknr = newblocknr; } curdata += BIGSIZE; } + r = S_OK; + err2: HeapFree(GetProcessHeap(),0,data); + if(r != S_OK) + return r; } /* generate big blocks to fit the new data */ lastblocknr = blocknr; diff --git a/dlls/setupapi/queue.c b/dlls/setupapi/queue.c index 59e06176a82..db7f7aed06d 100644 --- a/dlls/setupapi/queue.c +++ b/dlls/setupapi/queue.c @@ -115,9 +115,9 @@ inline static void queue_file_op( struct file_op_queue *queue, struct file_op *o /* free all the file operations on a given queue */ static void free_file_op_queue( struct file_op_queue *queue ) { - struct file_op *op; + struct file_op *t, *op = queue->head; - for (op = queue->head; op; op = op->next) + while( op ) { HeapFree( GetProcessHeap(), 0, op->src_root ); HeapFree( GetProcessHeap(), 0, op->src_path ); @@ -126,6 +126,9 @@ static void free_file_op_queue( struct file_op_queue *queue ) HeapFree( GetProcessHeap(), 0, op->src_tag ); HeapFree( GetProcessHeap(), 0, op->dst_path ); if (op->dst_file != op->src_file) HeapFree( GetProcessHeap(), 0, op->dst_file ); + t = op; + op = op->next; + HeapFree( GetProcessHeap(), 0, t ); } } diff --git a/dlls/user/lstr.c b/dlls/user/lstr.c index a7f0515b6c6..dbf99b15a60 100644 --- a/dlls/user/lstr.c +++ b/dlls/user/lstr.c @@ -711,6 +711,7 @@ DWORD WINAPI FormatMessage16( b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz); } for (x=b; *x; x++) ADD_TO_T(*x); + HeapFree(GetProcessHeap(), 0, b); } else { /* NULL args - copy formatstr * (probably wrong) diff --git a/dlls/x11drv/winpos.c b/dlls/x11drv/winpos.c index c4be59f694c..dd3df9b6692 100644 --- a/dlls/x11drv/winpos.c +++ b/dlls/x11drv/winpos.c @@ -1053,6 +1053,7 @@ static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt ) /* No window was found, so it's OK for us */ pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2; pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2; + HeapFree( GetProcessHeap(), 0, list ); return pt; } while(x <= rectParent.right-xspacing); diff --git a/graphics/path.c b/graphics/path.c index 522066d0958..befd3452a8c 100644 --- a/graphics/path.c +++ b/graphics/path.c @@ -1222,15 +1222,16 @@ static BOOL PATH_PathToRegion(GdiPath *pPath, INT nPolyFillMode, /* Create a region from the strokes */ hrgn=CreatePolyPolygonRgn(pPath->pPoints, pNumPointsInStroke, numStrokes, nPolyFillMode); + + /* Free memory for number-of-points-in-stroke array */ + HeapFree( GetProcessHeap(), 0, pNumPointsInStroke ); + if(hrgn==(HRGN)0) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; } - /* Free memory for number-of-points-in-stroke array */ - HeapFree( GetProcessHeap(), 0, pNumPointsInStroke ); - /* Success! */ *pHrgn=hrgn; return TRUE;