Lots more memory/resource leak fixes. There are still more, but this solves about 75% of them.
These fixes also speed up tex2rtf greatly. I can now build all the RTF version of the wxWindows manual in under 30 seconds, when before it took around 90 seconds. Curley Brace matching is turned back on again. I cannot find any places where it does not work. If you find one, let me know git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8773 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -28,6 +28,10 @@
|
|||||||
#include "tex2rtf.h"
|
#include "tex2rtf.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern wxHashTable TexReferences;
|
||||||
|
|
||||||
|
|
||||||
extern void DecToHex(int, char *);
|
extern void DecToHex(int, char *);
|
||||||
void GenerateHTMLIndexFile(char *fname);
|
void GenerateHTMLIndexFile(char *fname);
|
||||||
|
|
||||||
|
@@ -58,6 +58,11 @@ extern FILE *WinHelpContentsFile;
|
|||||||
extern char *RTFCharset;
|
extern char *RTFCharset;
|
||||||
// This is defined in the Tex2Any library and isn't in use after parsing
|
// This is defined in the Tex2Any library and isn't in use after parsing
|
||||||
extern char *BigBuffer;
|
extern char *BigBuffer;
|
||||||
|
|
||||||
|
|
||||||
|
extern wxHashTable TexReferences;
|
||||||
|
|
||||||
|
|
||||||
// Are we in verbatim mode? If so, format differently.
|
// Are we in verbatim mode? If so, format differently.
|
||||||
static bool inVerbatim = FALSE;
|
static bool inVerbatim = FALSE;
|
||||||
|
|
||||||
@@ -3482,6 +3487,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
|
|||||||
// Convert points to TWIPS (1 twip = 1/20th of point)
|
// Convert points to TWIPS (1 twip = 1/20th of point)
|
||||||
imageWidth = (int)(20*(tok1 ? ParseUnitArgument(tok1) : 0));
|
imageWidth = (int)(20*(tok1 ? ParseUnitArgument(tok1) : 0));
|
||||||
imageHeight = (int)(20*(tok2 ? ParseUnitArgument(tok2) : 0));
|
imageHeight = (int)(20*(tok2 ? ParseUnitArgument(tok2) : 0));
|
||||||
|
if (imageDimensions) // glt
|
||||||
|
delete [] imageDimensions;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else if (start && (arg_no == 2 ))
|
else if (start && (arg_no == 2 ))
|
||||||
@@ -3556,6 +3563,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
|
|||||||
sprintf(buf, "Warning: could not find a BMP or WMF equivalent for %s.", filename);
|
sprintf(buf, "Warning: could not find a BMP or WMF equivalent for %s.", filename);
|
||||||
OnInform(buf);
|
OnInform(buf);
|
||||||
}
|
}
|
||||||
|
if (filename) // glt
|
||||||
|
delete [] filename;
|
||||||
}
|
}
|
||||||
else // linear RTF
|
else // linear RTF
|
||||||
{
|
{
|
||||||
@@ -5218,15 +5227,20 @@ bool RTFGo(void)
|
|||||||
{
|
{
|
||||||
wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
|
wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
|
||||||
Tex2RTFYield(TRUE);
|
Tex2RTFYield(TRUE);
|
||||||
if (FileExists(OutputFile)) wxRemoveFile(OutputFile);
|
if (FileExists(OutputFile))
|
||||||
wxString cwdStr, outputDirStr;
|
wxRemoveFile(OutputFile);
|
||||||
|
|
||||||
|
char *cwdStr;
|
||||||
cwdStr = wxGetWorkingDirectory();
|
cwdStr = wxGetWorkingDirectory();
|
||||||
|
|
||||||
|
wxString outputDirStr;
|
||||||
outputDirStr = wxPathOnly(OutputFile);
|
outputDirStr = wxPathOnly(OutputFile);
|
||||||
|
|
||||||
// Determine if the temp file and the output file are in the same directory,
|
// Determine if the temp file and the output file are in the same directory,
|
||||||
// and if they are, then just rename the temp file rather than copying
|
// and if they are, then just rename the temp file rather than copying
|
||||||
// it, as this is much faster when working with large (multi-megabyte files)
|
// it, as this is much faster when working with large (multi-megabyte files)
|
||||||
if ((wxStrcmp(wxPathOnly(OutputFile),"") == 0) || // no path specified on output file
|
if ((wxStrcmp(outputDirStr.c_str(),"") == 0) || // no path specified on output file
|
||||||
(wxStrcmp(wxGetWorkingDirectory(),wxPathOnly(OutputFile)) == 0)) // paths do not match
|
(wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match
|
||||||
{
|
{
|
||||||
wxRenameFile("tmp1.rtf", OutputFile);
|
wxRenameFile("tmp1.rtf", OutputFile);
|
||||||
}
|
}
|
||||||
@@ -5234,6 +5248,7 @@ bool RTFGo(void)
|
|||||||
{
|
{
|
||||||
wxCopyFile("tmp1.rtf", OutputFile);
|
wxCopyFile("tmp1.rtf", OutputFile);
|
||||||
}
|
}
|
||||||
|
delete [] cwdStr;
|
||||||
Tex2RTFYield(TRUE);
|
Tex2RTFYield(TRUE);
|
||||||
wxRemoveFile("tmp1.rtf");
|
wxRemoveFile("tmp1.rtf");
|
||||||
}
|
}
|
||||||
|
@@ -123,6 +123,10 @@ char *followedLinkColourString = NULL;
|
|||||||
bool combineSubSections = FALSE;
|
bool combineSubSections = FALSE;
|
||||||
bool htmlWorkshopFiles = FALSE;
|
bool htmlWorkshopFiles = FALSE;
|
||||||
|
|
||||||
|
extern int passNumber;
|
||||||
|
|
||||||
|
extern wxHashTable TexReferences;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* International support
|
* International support
|
||||||
*/
|
*/
|
||||||
@@ -191,6 +195,32 @@ TexMacroDef *VerbatimMacroDef = NULL;
|
|||||||
|
|
||||||
#define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
|
#define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
|
||||||
|
|
||||||
|
|
||||||
|
TexRef::TexRef(char *label, char *file, char *section, char *sectionN)
|
||||||
|
{
|
||||||
|
refLabel = copystring(label);
|
||||||
|
refFile = file ? copystring(file) : (char*) NULL;
|
||||||
|
sectionNumber = section ? copystring(section) : copystring("??");
|
||||||
|
sectionName = sectionN ? copystring(sectionN) : copystring("??");
|
||||||
|
}
|
||||||
|
|
||||||
|
TexRef::~TexRef(void)
|
||||||
|
{
|
||||||
|
delete [] refLabel; refLabel = NULL;
|
||||||
|
delete [] refFile; refFile = NULL;
|
||||||
|
delete [] sectionNumber; sectionNumber = NULL;
|
||||||
|
delete [] sectionName; sectionName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CustomMacro::~CustomMacro()
|
||||||
|
{
|
||||||
|
if (macroName)
|
||||||
|
delete [] macroName;
|
||||||
|
if (macroBody)
|
||||||
|
delete [] macroBody;
|
||||||
|
}
|
||||||
|
|
||||||
void TexOutput(char *s, bool ordinaryText)
|
void TexOutput(char *s, bool ordinaryText)
|
||||||
{
|
{
|
||||||
int len = strlen(s);
|
int len = strlen(s);
|
||||||
@@ -365,7 +395,7 @@ bool readInVerbatim = FALSE; // Within a verbatim, but not nec. verbatiminput
|
|||||||
|
|
||||||
// Switched this off because e.g. \verb${$ causes it to fail. There is no
|
// Switched this off because e.g. \verb${$ causes it to fail. There is no
|
||||||
// detection of \verb yet.
|
// detection of \verb yet.
|
||||||
#define CHECK_BRACES 0
|
#define CHECK_BRACES 1
|
||||||
|
|
||||||
unsigned long leftCurly = 0;
|
unsigned long leftCurly = 0;
|
||||||
unsigned long rightCurly = 0;
|
unsigned long rightCurly = 0;
|
||||||
@@ -400,7 +430,7 @@ bool read_a_line(char *buf)
|
|||||||
if (rightCurly > leftCurly)
|
if (rightCurly > leftCurly)
|
||||||
{
|
{
|
||||||
wxString errBuf;
|
wxString errBuf;
|
||||||
errBuf.Printf("An extra right Curly brace ('}') was detected at line %l inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
|
errBuf.Printf("An extra right Curly brace ('}') was detected at line %lu inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
|
||||||
OnError((char *)errBuf.c_str());
|
OnError((char *)errBuf.c_str());
|
||||||
|
|
||||||
// Reduce the count of right curly braces, so the mismatched count
|
// Reduce the count of right curly braces, so the mismatched count
|
||||||
@@ -1451,6 +1481,7 @@ int ParseMacroBody(char *macro_name, TexChunk *parent,
|
|||||||
|
|
||||||
bool TexLoadFile(char *filename)
|
bool TexLoadFile(char *filename)
|
||||||
{
|
{
|
||||||
|
static char *line_buffer;
|
||||||
stopRunning = FALSE;
|
stopRunning = FALSE;
|
||||||
strcpy(TexFileRoot, filename);
|
strcpy(TexFileRoot, filename);
|
||||||
StripExtension(TexFileRoot);
|
StripExtension(TexFileRoot);
|
||||||
@@ -1459,10 +1490,12 @@ bool TexLoadFile(char *filename)
|
|||||||
|
|
||||||
TexPathList.EnsureFileAccessible(filename);
|
TexPathList.EnsureFileAccessible(filename);
|
||||||
|
|
||||||
|
if (line_buffer)
|
||||||
|
delete line_buffer;
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
static char *line_buffer = new char[600];
|
line_buffer = new char[600];
|
||||||
#else
|
#else
|
||||||
static char *line_buffer = new char[11000];
|
line_buffer = new char[11000];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Inputs[0] = fopen(filename, "r");
|
Inputs[0] = fopen(filename, "r");
|
||||||
@@ -1818,7 +1851,16 @@ void TexCleanUp(void)
|
|||||||
BibliographyStyleString = copystring("plain");
|
BibliographyStyleString = copystring("plain");
|
||||||
DocumentStyleString = copystring("report");
|
DocumentStyleString = copystring("report");
|
||||||
MinorDocumentStyleString = NULL;
|
MinorDocumentStyleString = NULL;
|
||||||
/* Don't want to remove custom macros after each pass.
|
|
||||||
|
// gt - Changed this so if this is the final pass
|
||||||
|
// then we DO want to remove these macros, so that
|
||||||
|
// memory is not MASSIVELY leaked if the user
|
||||||
|
// does not exit the program, but instead runs
|
||||||
|
// the program again
|
||||||
|
if ((passNumber == 1 && !runTwice) ||
|
||||||
|
(passNumber == 2 && runTwice))
|
||||||
|
{
|
||||||
|
/* Don't want to remove custom macros after each pass.*/
|
||||||
SetFontSizes(10);
|
SetFontSizes(10);
|
||||||
wxNode *node = CustomMacroList.First();
|
wxNode *node = CustomMacroList.First();
|
||||||
while (node)
|
while (node)
|
||||||
@@ -1828,7 +1870,8 @@ void TexCleanUp(void)
|
|||||||
delete node;
|
delete node;
|
||||||
node = CustomMacroList.First();
|
node = CustomMacroList.First();
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
/**/
|
||||||
TexReferences.BeginFind();
|
TexReferences.BeginFind();
|
||||||
wxNode *node = TexReferences.Next();
|
wxNode *node = TexReferences.Next();
|
||||||
while (node)
|
while (node)
|
||||||
|
@@ -387,21 +387,10 @@ class TexRef: public wxObject
|
|||||||
char *refFile; // Reference filename (can be NULL)
|
char *refFile; // Reference filename (can be NULL)
|
||||||
char *sectionNumber; // Section or figure number (as a string)
|
char *sectionNumber; // Section or figure number (as a string)
|
||||||
char *sectionName; // name e.g. 'section'
|
char *sectionName; // name e.g. 'section'
|
||||||
TexRef(char *label, char *file, char *section, char *sectionN = NULL)
|
TexRef(char *label, char *file, char *section, char *sectionN = NULL);
|
||||||
{
|
~TexRef(void);
|
||||||
refLabel = copystring(label);
|
|
||||||
refFile = file ? copystring(file) : (char*) NULL;
|
|
||||||
sectionNumber = section ? copystring(section) : copystring("??");
|
|
||||||
sectionName = sectionN ? copystring(sectionN) : copystring("??");
|
|
||||||
}
|
|
||||||
~TexRef(void)
|
|
||||||
{
|
|
||||||
delete[] refLabel; delete[] refFile; delete[] sectionNumber; delete[] sectionName;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern wxHashTable TexReferences;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a reference
|
* Add a reference
|
||||||
*
|
*
|
||||||
@@ -511,6 +500,7 @@ class CustomMacro: public wxObject
|
|||||||
else
|
else
|
||||||
macroBody = NULL;
|
macroBody = NULL;
|
||||||
}
|
}
|
||||||
|
~CustomMacro();
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ReadCustomMacros(char *filename);
|
bool ReadCustomMacros(char *filename);
|
||||||
|
@@ -66,6 +66,27 @@ extern char *TexBibName; // Bibliography output file name
|
|||||||
extern char *TexTmpBibName; // Temporary bibliography output file name
|
extern char *TexTmpBibName; // Temporary bibliography output file name
|
||||||
extern wxList ColourTable;
|
extern wxList ColourTable;
|
||||||
extern TexChunk *TopLevel;
|
extern TexChunk *TopLevel;
|
||||||
|
extern char *PageStyle;
|
||||||
|
extern char *BibliographyStyleString;
|
||||||
|
extern char *DocumentStyleString;
|
||||||
|
extern char *bitmapMethod;
|
||||||
|
extern char *backgroundColourString;
|
||||||
|
extern char *ContentsNameString;
|
||||||
|
extern char *AbstractNameString;
|
||||||
|
extern char *GlossaryNameString;
|
||||||
|
extern char *ReferencesNameString;
|
||||||
|
extern char *FiguresNameString;
|
||||||
|
extern char *TablesNameString;
|
||||||
|
extern char *FigureNameString;
|
||||||
|
extern char *TableNameString;
|
||||||
|
extern char *IndexNameString;
|
||||||
|
extern char *ChapterNameString;
|
||||||
|
extern char *SectionNameString;
|
||||||
|
extern char *SubsectionNameString;
|
||||||
|
extern char *SubsubsectionNameString;
|
||||||
|
extern char *UpNameString;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_HELP
|
#if wxUSE_HELP
|
||||||
wxHelpController *HelpInstance = NULL;
|
wxHelpController *HelpInstance = NULL;
|
||||||
@@ -390,7 +411,10 @@ bool MyApp::OnInit()
|
|||||||
ReadCustomMacros((char*) (const char*) path);
|
ReadCustomMacros((char*) (const char*) path);
|
||||||
|
|
||||||
Go();
|
Go();
|
||||||
if (runTwice) Go();
|
if (runTwice)
|
||||||
|
{
|
||||||
|
Go();
|
||||||
|
}
|
||||||
#ifdef NO_GUI
|
#ifdef NO_GUI
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
@@ -507,6 +531,28 @@ int MyApp::OnExit()
|
|||||||
RTFCharset = NULL;
|
RTFCharset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete [] PageStyle;
|
||||||
|
delete [] BibliographyStyleString;
|
||||||
|
delete [] DocumentStyleString;
|
||||||
|
delete [] bitmapMethod;
|
||||||
|
delete [] backgroundColourString;
|
||||||
|
delete [] ContentsNameString;
|
||||||
|
delete [] AbstractNameString;
|
||||||
|
delete [] GlossaryNameString;
|
||||||
|
delete [] ReferencesNameString;
|
||||||
|
delete [] FiguresNameString;
|
||||||
|
delete [] TablesNameString;
|
||||||
|
delete [] FigureNameString;
|
||||||
|
delete [] TableNameString;
|
||||||
|
delete [] IndexNameString;
|
||||||
|
delete [] ChapterNameString;
|
||||||
|
delete [] SectionNameString;
|
||||||
|
delete [] SubsectionNameString;
|
||||||
|
delete [] SubsubsectionNameString;
|
||||||
|
delete [] UpNameString;
|
||||||
|
if (winHelpTitle)
|
||||||
|
delete[] winHelpTitle;
|
||||||
|
|
||||||
// TODO: this simulates zero-memory leaks!
|
// TODO: this simulates zero-memory leaks!
|
||||||
// Otherwise there are just too many...
|
// Otherwise there are just too many...
|
||||||
#ifndef __WXGTK__
|
#ifndef __WXGTK__
|
||||||
|
@@ -432,7 +432,14 @@ void ReadTexReferences(char *filename)
|
|||||||
istr.get(ch);
|
istr.get(ch);
|
||||||
}
|
}
|
||||||
section[i] = 0;
|
section[i] = 0;
|
||||||
|
|
||||||
|
// gt - needed to trick the hash table "TexReferences" into deleting the key
|
||||||
|
// strings it creates in the Put() function, but not the item that is
|
||||||
|
// created here, as that is destroyed elsewhere. Without doing this, there
|
||||||
|
// were massive memory leaks
|
||||||
|
TexReferences.DeleteContents(TRUE);
|
||||||
TexReferences.Put(label, new TexRef(label, file, section, sectionName));
|
TexReferences.Put(label, new TexRef(label, file, section, sectionName));
|
||||||
|
TexReferences.DeleteContents(FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,10 @@ wxList hyperLinks(wxKEY_INTEGER);
|
|||||||
wxList hyperLabels(wxKEY_STRING);
|
wxList hyperLabels(wxKEY_STRING);
|
||||||
FILE *Index = NULL;
|
FILE *Index = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
extern wxHashTable TexReferences;
|
||||||
|
|
||||||
|
|
||||||
void PadToTab(int tabPos)
|
void PadToTab(int tabPos)
|
||||||
{
|
{
|
||||||
int currentCol = GetCurrentColumn();
|
int currentCol = GetCurrentColumn();
|
||||||
|
Reference in New Issue
Block a user