[PATCH] comctl32/button: Delay calling get_button_text until it is needed to prevent a leak

Zhiyi Zhang zzhang at codeweavers.com
Fri Apr 5 06:44:16 CDT 2019


Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>

On 3/25/19 9:31 PM, Gabriel Ivăncescu wrote:
> Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
> ---
>
> Mostly from a copy-paste mistake, sorry about that.
>
>  dlls/comctl32/button.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c
> index f7497a1..97c66ea 100644
> --- a/dlls/comctl32/button.c
> +++ b/dlls/comctl32/button.c
> @@ -1969,10 +1969,10 @@ static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, in
>      RECT bgRect, textRect;
>      HFONT font = infoPtr->font;
>      HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL;
> -    WCHAR *text = get_button_text(infoPtr);
>      NMCUSTOMDRAW nmcd;
>      LRESULT cdrf;
>      HWND parent;
> +    WCHAR *text;
>  
>      GetClientRect(infoPtr->hwnd, &bgRect);
>      GetThemeBackgroundContentRect(theme, hDC, BP_PUSHBUTTON, state, &bgRect, &textRect);
> @@ -2000,10 +2000,9 @@ static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, in
>      cdrf = SendMessageW(parent, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
>      if (cdrf & CDRF_SKIPDEFAULT) goto cleanup;
>  
> -    if (text)
> +    if (!(cdrf & CDRF_DOERASE) && (text = get_button_text(infoPtr)))
>      {
> -        if (!(cdrf & CDRF_DOERASE))
> -            DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect);
> +        DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect);
>          heap_free(text);
>      }
>  
> @@ -2041,11 +2040,11 @@ static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, in
>      DWORD dwStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
>      UINT btn_type = get_button_type( dwStyle );
>      int part = (btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX;
> -    WCHAR *text = get_button_text(infoPtr);
>      NMCUSTOMDRAW nmcd;
>      LRESULT cdrf;
>      LOGFONTW lf;
>      HWND parent;
> +    WCHAR *text;
>      BOOL created_font = FALSE;
>  
>      HRESULT hr = GetThemeFont(theme, hDC, part, state, TMT_FONT, &lf);
> @@ -2099,6 +2098,7 @@ static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, in
>      cdrf = SendMessageW(parent, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
>      if (cdrf & CDRF_SKIPDEFAULT) goto cleanup;
>  
> +    text = get_button_text(infoPtr);
>      if (!(cdrf & CDRF_DOERASE) && text)
>          DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect);
>  
> @@ -2107,11 +2107,10 @@ static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, in
>          nmcd.dwDrawStage = CDDS_POSTPAINT;
>          SendMessageW(parent, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
>      }
> -    if (cdrf & CDRF_SKIPPOSTPAINT) goto cleanup;
>  
>      if (text)
>      {
> -        if (focused)
> +        if (!(cdrf & CDRF_SKIPPOSTPAINT) && focused)
>          {
>              RECT focusRect;
>  




More information about the wine-devel mailing list