From b5c031b1604fa6d7045ebfc016e0d013cfad6a10 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Thu, 2 Nov 2006 17:25:35 +0900 Subject: [PATCH] riched20: Initialize and free the RTF lookup table in DllMain to avoid memory leaks. --- dlls/riched20/editor.c | 2 ++ dlls/riched20/reader.c | 50 +++++++++++++++++++++++------------------- dlls/riched20/rtf.h | 3 +++ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 93aed91441f..48eb33d68e3 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -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; diff --git a/dlls/riched20/reader.c b/dlls/riched20/reader.c index 37f14355adf..67eac7c8420 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[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++) { - memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable)); - for (rp = rtfKey; rp->rtfKStr != NULL; rp++) { - int index; + 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; + 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; irtfMinor) { 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 611ce9aa9c1..be36a93e0e1 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