[PATCH 16/18] [RichEdit]: fixed object leaks generated by context creation & destruction
Eric Pouech
eric.pouech at orange.fr
Sun Mar 16 15:48:13 CDT 2008
A+
---
dlls/riched20/caret.c | 5 ++---
dlls/riched20/context.c | 3 ++-
dlls/riched20/editor.h | 2 +-
dlls/riched20/paint.c | 2 +-
dlls/riched20/para.c | 7 ++-----
dlls/riched20/run.c | 4 ++--
dlls/riched20/wrap.c | 15 +++++----------
7 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 18204e2..a6a6217 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -215,9 +215,8 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
*height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent;
*x = run->member.run.pt.x + sz.cx;
*y = para->member.para.nYPos + row->member.row.nBaseline + pSizeRun->member.run.pt.y - pSizeRun->member.run.nAscent - ME_GetYScrollPos(editor);
-
- ME_DestroyContext(&c);
- ReleaseDC(editor->hWnd, hDC);
+
+ ME_DestroyContext(&c, editor->hWnd);
return;
}
}
diff --git a/dlls/riched20/context.c b/dlls/riched20/context.c
index 56e68f7..161a64a 100644
--- a/dlls/riched20/context.c
+++ b/dlls/riched20/context.c
@@ -33,7 +33,8 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
c->dpi.cy = GetDeviceCaps(hDC, LOGPIXELSY);
}
-void ME_DestroyContext(ME_Context *c)
+void ME_DestroyContext(ME_Context *c, HWND hWnd)
{
+ if (hWnd) ReleaseDC(hWnd, c->hDC);
DeleteObject(c->hbrMargin);
}
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 7b9be5e..0c0d324 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -190,7 +190,7 @@ void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor);
BOOL ME_ArrowKey(ME_TextEditor *ed, int nVKey, BOOL extend, BOOL ctrl);
void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC);
-void ME_DestroyContext(ME_Context *c);
+void ME_DestroyContext(ME_Context *c, HWND release);
ME_Style *GetInsertStyle(ME_TextEditor *editor, int nCursor);
void ME_MustBeWrapped(ME_Context *c, ME_DisplayItem *para);
void ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
diff --git a/dlls/riched20/paint.c b/dlls/riched20/paint.c
index 91d5ec0..d5cb3c7 100644
--- a/dlls/riched20/paint.c
+++ b/dlls/riched20/paint.c
@@ -91,7 +91,7 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *
if (editor->nTotalLength != editor->nLastTotalLength)
ME_SendRequestResize(editor, FALSE);
editor->nLastTotalLength = editor->nTotalLength;
- ME_DestroyContext(&c);
+ ME_DestroyContext(&c, NULL);
}
void ME_Repaint(ME_TextEditor *editor)
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index 4fb24e9..b2f8e6c 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -28,7 +28,6 @@ static const WCHAR wszParagraphSign[] = {0xB6, 0};
void ME_MakeFirstParagraph(ME_TextEditor *editor)
{
ME_Context c;
- HDC hDC;
PARAFORMAT2 fmt;
CHARFORMAT2W cf;
LOGFONTW lf;
@@ -38,9 +37,8 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
ME_DisplayItem *run;
ME_Style *style;
- hDC = GetDC(editor->hWnd);
+ ME_InitContext(&c, editor, GetDC(editor->hWnd));
- ME_InitContext(&c, editor, hDC);
hf = (HFONT)GetStockObject(SYSTEM_FONT);
assert(hf);
GetObjectW(hf, sizeof(LOGFONTW), &lf);
@@ -85,8 +83,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
text->pLast->member.para.nCharOfs = 1;
- ME_DestroyContext(&c);
- ReleaseDC(editor->hWnd, hDC);
+ ME_DestroyContext(&c, editor->hWnd);
}
void ME_MarkAllForWrapping(ME_TextEditor *editor)
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index a762695..e193bd2 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -551,7 +551,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
{
SIZE sz;
ME_GetOLEObjectSize(&c, run, &sz);
- ReleaseDC(editor->hWnd, c.hDC);
+ ME_DestroyContext(&c, editor->hWnd);
if (cx < sz.cx/2)
return 0;
return 1;
@@ -580,7 +580,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
ME_DestroyString(strRunText);
ME_UnselectStyleFont(&c, run->style, hOldFont);
- ReleaseDC(editor->hWnd, c.hDC);
+ ME_DestroyContext(&c, editor->hWnd);
return fit;
}
diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index 49c5366..cd052a7 100644
--- a/dlls/riched20/wrap.c
+++ b/dlls/riched20/wrap.c
@@ -467,14 +467,12 @@ static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) {
}
BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
- HWND hWnd = editor->hWnd;
- HDC hDC = GetDC(hWnd);
ME_DisplayItem *item;
ME_Context c;
BOOL bModified = FALSE;
int yStart = -1, yEnd = -1;
- ME_InitContext(&c, editor, hDC);
+ ME_InitContext(&c, editor, GetDC(editor->hWnd));
c.pt.x = 0;
c.pt.y = 0;
editor->nHeight = 0;
@@ -510,9 +508,8 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
editor->nTotalLength = c.pt.y;
- ME_DestroyContext(&c);
- ReleaseDC(hWnd, hDC);
-
+ ME_DestroyContext(&c, editor->hWnd);
+
if (bModified || editor->nTotalLength < editor->nLastTotalLength)
ME_InvalidateMarkedParagraphs(editor);
return bModified;
@@ -520,9 +517,8 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) {
ME_Context c;
- HDC hDC = GetDC(editor->hWnd);
- ME_InitContext(&c, editor, hDC);
+ ME_InitContext(&c, editor, GetDC(editor->hWnd));
if (editor->bRedraw)
{
RECT rc = c.rcView;
@@ -544,8 +540,7 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) {
InvalidateRect(editor->hWnd, &rc, TRUE);
}
}
- ME_DestroyContext(&c);
- ReleaseDC(editor->hWnd, hDC);
+ ME_DestroyContext(&c, editor->hWnd);
}
More information about the wine-patches
mailing list