riched20: Initialize and free the RTF lookup table in DllMain to avoid memory leaks.

This commit is contained in:
Mike McCormack 2006-11-02 17:25:35 +09:00 committed by Alexandre Julliard
parent 14ec1d0c4c
commit b5c031b160
3 changed files with 32 additions and 23 deletions

View File

@ -1245,6 +1245,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
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, DWORD fdwReason, LPVOID lpvReserved)
UnregisterClassW(wszClassNameListBox, 0);
if (ME_ComboBoxRegistered)
UnregisterClassW(wszClassNameComboBox, 0);
LookupCleanup();
HeapDestroy (me_heap);
me_heap = NULL;
break;

View File

@ -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++)
@ -2325,15 +2321,13 @@ static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT * 2];
* 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++) {
for (rp = rtfKey; rp->rtfKStr != NULL; rp++)
{
int index;
rp->rtfKHash = Hash (rp->rtfKStr);
@ -2344,7 +2338,17 @@ static void LookupInit(void)
rtfHashTable[index].value = RTFReAlloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
}
++inited;
}
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;
}
}

View File

@ -1147,4 +1147,7 @@ int BeginFile (RTF_Info *);
int RTFCharSetToCodePage(RTF_Info *info, int charset);
void LookupInit (void);
void LookupCleanup (void);
#endif