From 00a386ebf93867b561ff1263ee921142441effa8 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Tue, 12 Jul 2011 16:12:04 +0100 Subject: [PATCH] gdi32: Simplify the optional free'ing of bits pointer. --- dlls/gdi32/dibdrv/dc.c | 19 ++++++++++--------- dlls/gdi32/dibdrv/dibdrv.h | 2 +- dlls/gdi32/dibdrv/objects.c | 4 ++-- dlls/gdi32/gdi_private.h | 1 + 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dlls/gdi32/dibdrv/dc.c b/dlls/gdi32/dibdrv/dc.c index 1f8b3216c32..575221bd884 100644 --- a/dlls/gdi32/dibdrv/dc.c +++ b/dlls/gdi32/dibdrv/dc.c @@ -74,6 +74,7 @@ static BOOL init_dib_info(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD dib->height = bi->biHeight; dib->stride = ((dib->width * dib->bit_count + 31) >> 3) & ~3; dib->bits = bits; + dib->ptr_to_free = NULL; if(dib->height < 0) /* top-down */ { @@ -197,6 +198,7 @@ static void clear_dib_info(dib_info *dib) { dib->color_table = NULL; dib->bits = NULL; + dib->ptr_to_free = NULL; } /********************************************************************** @@ -204,15 +206,14 @@ static void clear_dib_info(dib_info *dib) * * Free the resources associated with a dib and optionally the bits */ -void free_dib_info(dib_info *dib, BOOL free_bits) +void free_dib_info(dib_info *dib) { HeapFree(GetProcessHeap(), 0, dib->color_table); dib->color_table = NULL; - if(free_bits) - { - HeapFree(GetProcessHeap(), 0, dib->bits); - dib->bits = NULL; - } + + HeapFree(GetProcessHeap(), 0, dib->ptr_to_free); + dib->ptr_to_free = NULL; + dib->bits = NULL; } void copy_dib_color_info(dib_info *dst, const dib_info *src) @@ -254,7 +255,7 @@ BOOL convert_dib(dib_info *dst, const dib_info *src) dst->height = src->height; dst->width = src->width; dst->stride = ((dst->width * dst->bit_count + 31) >> 3) & ~3; - dst->bits = HeapAlloc(GetProcessHeap(), 0, dst->height * dst->stride); + dst->ptr_to_free = dst->bits = HeapAlloc(GetProcessHeap(), 0, dst->height * dst->stride); src_rect.left = src_rect.top = 0; src_rect.right = src->width; @@ -262,7 +263,7 @@ BOOL convert_dib(dib_info *dst, const dib_info *src) ret = dst->funcs->convert_to(dst, src, &src_rect); - if(!ret) free_dib_info(dst, TRUE); + if(!ret) free_dib_info(dst); return ret; } @@ -289,7 +290,7 @@ static BOOL CDECL dibdrv_DeleteDC( PHYSDEV dev ) TRACE("(%p)\n", dev); DeleteObject(pdev->clip); free_pattern_brush(pdev); - free_dib_info(&pdev->dib, FALSE); + free_dib_info(&pdev->dib); return 0; } diff --git a/dlls/gdi32/dibdrv/dibdrv.h b/dlls/gdi32/dibdrv/dibdrv.h index 9fde40af681..e142a9b034c 100644 --- a/dlls/gdi32/dibdrv/dibdrv.h +++ b/dlls/gdi32/dibdrv/dibdrv.h @@ -60,7 +60,7 @@ extern void calc_and_xor_masks(INT rop, DWORD color, DWORD *and, DWORD *xor) DEC extern void update_brush_rop( dibdrv_physdev *pdev, INT rop ) DECLSPEC_HIDDEN; extern void reset_dash_origin(dibdrv_physdev *pdev) DECLSPEC_HIDDEN; extern BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD usage, HPALETTE pal) DECLSPEC_HIDDEN; -extern void free_dib_info(dib_info *dib, BOOL free_bits) DECLSPEC_HIDDEN; +extern void free_dib_info(dib_info *dib) DECLSPEC_HIDDEN; extern void free_pattern_brush(dibdrv_physdev *pdev) DECLSPEC_HIDDEN; extern void copy_dib_color_info(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN; extern BOOL convert_dib(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN; diff --git a/dlls/gdi32/dibdrv/objects.c b/dlls/gdi32/dibdrv/objects.c index 69faaeba015..1a3e989ccbe 100644 --- a/dlls/gdi32/dibdrv/objects.c +++ b/dlls/gdi32/dibdrv/objects.c @@ -1072,7 +1072,7 @@ static void free_pattern_brush_bits( dibdrv_physdev *pdev ) void free_pattern_brush( dibdrv_physdev *pdev ) { free_pattern_brush_bits( pdev ); - free_dib_info( &pdev->brush_dib, TRUE ); + free_dib_info( &pdev->brush_dib ); } static BOOL create_pattern_brush_bits(dibdrv_physdev *pdev) @@ -1295,7 +1295,7 @@ HBRUSH CDECL dibdrv_SelectBrush( PHYSDEV dev, HBRUSH hbrush ) pdev->brush_rects = pattern_brush; pdev->defer &= ~DEFER_BRUSH; } - free_dib_info(&orig_dib, FALSE); + free_dib_info(&orig_dib); } GlobalUnlock((HGLOBAL)logbrush.lbHatch); break; diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index 2d8ea5d15b8..c5ff4bafb5e 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -78,6 +78,7 @@ typedef struct int bit_count, width, height; int stride; /* stride in bytes. Will be -ve for bottom-up dibs (see bits). */ void *bits; /* points to the top-left corner of the dib. */ + void *ptr_to_free; DWORD red_mask, green_mask, blue_mask; int red_shift, green_shift, blue_shift;