Mike McCormack : riched20:
Initialize and free the RTF lookup table in DllMain to avoid memory
leaks.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Nov 2 05:46:47 CST 2006
Module: wine
Branch: master
Commit: b5c031b1604fa6d7045ebfc016e0d013cfad6a10
URL: http://source.winehq.org/git/wine.git/?a=commit;h=b5c031b1604fa6d7045ebfc016e0d013cfad6a10
Author: Mike McCormack <mike at codeweavers.com>
Date: Thu Nov 2 17:25:35 2006 +0900
riched20: Initialize and free the RTF lookup table in DllMain to avoid memory leaks.
---
dlls/riched20/editor.c | 2 +
dlls/riched20/reader.c | 52 +++++++++++++++++++++++++----------------------
dlls/riched20/rtf.h | 3 ++
3 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 93aed91..48eb33d 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1245,6 +1245,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL,
DisableThreadLibraryCalls(hinstDLL);
me_heap = HeapCreate (0, 0x10000, 0);
ME_RegisterEditorClass(hinstDLL);
+ LookupInit();
break;
case DLL_PROCESS_DETACH:
@@ -1256,6 +1257,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL,
UnregisterClassW(wszClassNameListBox, 0);
if (ME_ComboBoxRegistered)
UnregisterClassW(wszClassNameComboBox, 0);
+ LookupCleanup();
HeapDestroy (me_heap);
me_heap = NULL;
break;
diff --git a/dlls/riched20/reader.c b/dlls/riched20/reader.c
index 37f1435..67eac7c 100644
--- a/dlls/riched20/reader.c
+++ b/dlls/riched20/reader.c
@@ -64,7 +64,6 @@ static void ReadStyleSheet (RTF_Info *);
static void ReadInfoGroup (RTF_Info *);
static void ReadPictGroup (RTF_Info *);
static void ReadObjGroup (RTF_Info *);
-static void LookupInit (void);
static void Lookup (RTF_Info *, char *);
static int Hash (const char *);
@@ -214,9 +213,6 @@ void RTFInit(RTF_Info *info)
RTFFree (info->outputName);
info->inputName = info->outputName = NULL;
- /* initialize lookup table */
- LookupInit ();
-
for (i = 0; i < rtfMaxClass; i++)
RTFSetClassCallback (info, i, NULL);
for (i = 0; i < rtfMaxDestination; i++)
@@ -1816,7 +1812,7 @@ static RTFKey rtfKey[] =
{ rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
{ rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
-
+
{ rtfDocAttr, rtfAnsiCodePage, "ansicpg", 0 },
{ rtfDocAttr, rtfUTF8RTF, "urtf", 0 },
@@ -2325,26 +2321,34 @@ static RTFHashTableEntry rtfHashTable[RT
* Initialize lookup table hash values. Only need to do this once.
*/
-static void LookupInit(void)
+void LookupInit(void)
{
- static int inited = 0;
RTFKey *rp;
- if (inited == 0)
+ memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable));
+ for (rp = rtfKey; rp->rtfKStr != NULL; rp++)
{
- memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable));
- for (rp = rtfKey; rp->rtfKStr != NULL; rp++) {
- int index;
-
- rp->rtfKHash = Hash (rp->rtfKStr);
- index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
- if (!rtfHashTable[index].count)
- rtfHashTable[index].value = RTFAlloc(sizeof(RTFKey *));
- else
- rtfHashTable[index].value = RTFReAlloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
- rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
- }
- ++inited;
+ int index;
+
+ rp->rtfKHash = Hash (rp->rtfKStr);
+ index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
+ if (!rtfHashTable[index].count)
+ rtfHashTable[index].value = RTFAlloc(sizeof(RTFKey *));
+ else
+ rtfHashTable[index].value = RTFReAlloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
+ rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
+ }
+}
+
+void LookupCleanup(void)
+{
+ int i;
+
+ for (i=0; i<RTF_KEY_COUNT*2; i++)
+ {
+ RTFFree( rtfHashTable[i].value );
+ rtfHashTable[i].value = NULL;
+ rtfHashTable[i].count = 0;
}
}
@@ -2524,7 +2528,7 @@ static void
CharAttr(RTF_Info *info)
{
RTFFont *font;
-
+
switch (info->rtfMinor)
{
case rtfFontNum:
@@ -2627,9 +2631,9 @@ static void SpecialChar (RTF_Info *info)
case rtfUnicode:
{
int i;
-
+
RTFPutUnicodeChar(info, info->rtfParam);
-
+
/* After \u we must skip number of character tokens set by \ucN */
for (i = 0; i < info->unicodeLength; i++)
{
diff --git a/dlls/riched20/rtf.h b/dlls/riched20/rtf.h
index 611ce9a..be36a93 100644
--- a/dlls/riched20/rtf.h
+++ b/dlls/riched20/rtf.h
@@ -1147,4 +1147,7 @@ int BeginFile (RTF_Info *);
int RTFCharSetToCodePage(RTF_Info *info, int charset);
+void LookupInit (void);
+void LookupCleanup (void);
+
#endif
More information about the wine-cvs
mailing list