0
0
mirror of https://github.com/vim/vim.git synced 2025-10-02 05:04:20 -04:00

patch 8.1.0652: freeing memory for balloon eval too early

Problem:    Freeing memory for balloon eval too early.
Solution:   Store the pointer in BalloonEval and free it later. (Yasuhiro
            Matsumoto, closes #3725)
This commit is contained in:
Bram Moolenaar
2018-12-28 19:13:34 +01:00
parent 2ac372ccee
commit 6d9e71ad99
3 changed files with 13 additions and 10 deletions

View File

@@ -76,6 +76,9 @@ typedef struct BalloonEvalStruct
int *vts; // vartabstop setting for this buffer int *vts; // vartabstop setting for this buffer
#endif #endif
char_u *msg; char_u *msg;
#ifdef FEAT_GUI_W32
void *tofree;
#endif
} BalloonEval; } BalloonEval;
#define EVAL_OFFSET_X 15 /* displacement of beval topleft corner from pointer */ #define EVAL_OFFSET_X 15 /* displacement of beval topleft corner from pointer */

View File

@@ -8787,7 +8787,6 @@ make_tooltipw(BalloonEval *beval, char *text, POINT pt)
{ {
TOOLINFOW *pti; TOOLINFOW *pti;
int ToolInfoSize; int ToolInfoSize;
WCHAR *tofree = NULL;
if (multiline_balloon_available() == TRUE) if (multiline_balloon_available() == TRUE)
ToolInfoSize = sizeof(TOOLINFOW_NEW); ToolInfoSize = sizeof(TOOLINFOW_NEW);
@@ -8817,8 +8816,8 @@ make_tooltipw(BalloonEval *beval, char *text, POINT pt)
RECT rect; RECT rect;
TOOLINFOW_NEW *ptin = (TOOLINFOW_NEW *)pti; TOOLINFOW_NEW *ptin = (TOOLINFOW_NEW *)pti;
pti->lpszText = LPSTR_TEXTCALLBACKW; pti->lpszText = LPSTR_TEXTCALLBACKW;
tofree = enc_to_utf16((char_u*)text, NULL); beval->tofree = enc_to_utf16((char_u*)text, NULL);
ptin->lParam = (LPARAM)tofree; ptin->lParam = (LPARAM)beval->tofree;
// switch multiline tooltips on // switch multiline tooltips on
if (GetClientRect(s_textArea, &rect)) if (GetClientRect(s_textArea, &rect))
SendMessageW(beval->balloon, TTM_SETMAXTIPWIDTH, 0, SendMessageW(beval->balloon, TTM_SETMAXTIPWIDTH, 0,
@@ -8827,8 +8826,8 @@ make_tooltipw(BalloonEval *beval, char *text, POINT pt)
else else
{ {
// do this old way // do this old way
tofree = enc_to_utf16((char_u*)text, NULL); beval->tofree = enc_to_utf16((char_u*)text, NULL);
pti->lpszText = tofree; pti->lpszText = (LPWSTR)beval->tofree;
} }
// Limit ballooneval bounding rect to CursorPos neighbourhood. // Limit ballooneval bounding rect to CursorPos neighbourhood.
@@ -8851,8 +8850,6 @@ make_tooltipw(BalloonEval *beval, char *text, POINT pt)
mouse_event(MOUSEEVENTF_MOVE, 2, 2, 0, 0); mouse_event(MOUSEEVENTF_MOVE, 2, 2, 0, 0);
mouse_event(MOUSEEVENTF_MOVE, (DWORD)-1, (DWORD)-1, 0, 0); mouse_event(MOUSEEVENTF_MOVE, (DWORD)-1, (DWORD)-1, 0, 0);
vim_free(pti); vim_free(pti);
if (tofree != NULL)
vim_free(tofree);
} }
#endif #endif
@@ -8898,7 +8895,8 @@ make_tooltip(BalloonEval *beval, char *text, POINT pt)
RECT rect; RECT rect;
TOOLINFO_NEW *ptin = (TOOLINFO_NEW *)pti; TOOLINFO_NEW *ptin = (TOOLINFO_NEW *)pti;
pti->lpszText = LPSTR_TEXTCALLBACK; pti->lpszText = LPSTR_TEXTCALLBACK;
ptin->lParam = (LPARAM)text; beval->tofree = vim_strsave((char_u*)text);
ptin->lParam = (LPARAM)beval->tofree;
if (GetClientRect(s_textArea, &rect)) /* switch multiline tooltips on */ if (GetClientRect(s_textArea, &rect)) /* switch multiline tooltips on */
SendMessage(beval->balloon, TTM_SETMAXTIPWIDTH, 0, SendMessage(beval->balloon, TTM_SETMAXTIPWIDTH, 0,
(LPARAM)rect.right); (LPARAM)rect.right);
@@ -9106,9 +9104,9 @@ TrackUserActivity(UINT uMsg)
gui_mch_destroy_beval_area(BalloonEval *beval) gui_mch_destroy_beval_area(BalloonEval *beval)
{ {
#ifdef FEAT_VARTABS #ifdef FEAT_VARTABS
if (beval->vts) vim_free(beval->vts);
vim_free(beval->vts);
#endif #endif
vim_free(beval->tofree);
vim_free(beval); vim_free(beval);
} }
#endif /* FEAT_BEVAL_GUI */ #endif /* FEAT_BEVAL_GUI */

View File

@@ -799,6 +799,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
652,
/**/ /**/
651, 651,
/**/ /**/