From 84b01259ef0357bdb1ecb1a7cc8537c3340da076 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 1 Aug 2001 16:48:06 +0000 Subject: [PATCH] fix (potential?) memory leaks; cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2403 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 5 +++++ src/mathed/formula.C | 5 +---- src/mathed/formulamacro.C | 1 + src/mathed/math_cursor.C | 5 +++++ src/mathed/math_cursor.h | 2 ++ src/mathed/math_macrotable.C | 24 +++++++---------------- src/mathed/math_parser.C | 38 ++++++++++++++++++------------------ 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index e5c4c4257c..610ec4362f 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ +2001-08-01 André Pönitz + + * math_cursor.C: + formulamacro.C: fix memory leaks + 2001-07-25 André Pönitz * formulabase.C: re-enable 'space enlargement' feature diff --git a/src/mathed/formula.C b/src/mathed/formula.C index af0bf736a1..940ef7c223 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -50,10 +50,6 @@ extern char const * latex_mathenv[]; extern MathCursor * mathcursor; -// quite a hack i know. Should be done with return values... -int number_of_newlines = 0; - - InsetFormula::InsetFormula() : InsetFormulaBase(new MathMatrixInset) {} @@ -316,6 +312,7 @@ MathMatrixInset * InsetFormula::par() const return static_cast(par_); } + void InsetFormula::par(MathInset * p) { delete par_; diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index c9f9450013..688b920063 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -96,6 +96,7 @@ int InsetFormulaMacro::docBook(ostream & os) const void InsetFormulaMacro::read(LyXLex & lex) { // Awful hack... + delete par_; par_ = mathed_parse(lex); MathMacroTable::insertTemplate(tmacro()); par_->metrics(LM_ST_TEXT); diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 03f9bd04f5..073716d3b4 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -132,6 +132,11 @@ MathCursor::MathCursor(InsetFormulaBase * formula) } +MathCursor::~MathCursor() +{ + delete imacro_; +} + void MathCursor::push(MathInset * par, bool first) { MathCursorPos p; diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 2fa59bd8ad..80e8a606fb 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -71,6 +71,8 @@ public: /// explicit MathCursor(InsetFormulaBase *); /// + ~MathCursor(); + /// void insert(char, MathTextCodes t = LM_TC_MIN); /// void insert(MathInset *); diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index ac2b4fa5e9..55928ab397 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -14,7 +14,6 @@ #include "math_fracinset.h" #include "debug.h" -using std::endl; MathArray mathed_parse_cell(string const &); @@ -28,20 +27,8 @@ void MathMacroTable::dump() table_type::const_iterator it; for (it = macro_table.begin(); it != macro_table.end(); ++it) lyxerr << it->first << " [" << it->second->nargs() << "] : " - << it->second << endl; - lyxerr << "------------------------------------------" << endl;; -} - - -void MathMacroTable::updateTemplate(MathMacroTemplate * par) -{ - table_type::iterator pos = macro_table.find(par->name()); - - if (pos == macro_table.end()) - lyxerr << "MathMacroTable::updateTemplate: no template with name '" - << par->name() << "' available." << endl; - else - pos->second = par; + << it->second << "\n"; + lyxerr << "------------------------------------------\n"; } @@ -59,7 +46,7 @@ MathMacroTemplate & MathMacroTable::provideTemplate(string const & name) if (pos == macro_table.end()) { lyxerr << "MathMacroTable::provideTemplate: no template with name '" - << name << "' available." << endl; + << name << "' available.\n"; } return *pos->second; @@ -72,6 +59,9 @@ void MathMacroTable::createTemplate MathMacroTemplate * t = new MathMacroTemplate(name, na); t->cell(0) = mathed_parse_cell(text); insertTemplate(t); +#ifdef WITH_WARNINGS +#warning who frees this? +#endif } @@ -96,7 +86,7 @@ void MathMacroTable::builtinMacros() return; built = true; - //lyxerr[Debug::MATHED] << "Building macros" << endl; + //lyxerr[Debug::MATHED] << "Building macros\n"; createTemplate("emptyset", 0, "\\not0"); createTemplate("ge", 0, "\\geq"); diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 6c4f0255ee..f3b95d443c 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -81,7 +81,7 @@ char const * latex_special_chars = "#$%&_{}"; namespace { -void mathed_parse(MathArray & array, unsigned flags); +void mathed_parse_into(MathArray & array, unsigned flags); unsigned char getuchar(std::istream * is) { @@ -399,8 +399,8 @@ void mathed_parse_lines(MathInset * inset, int col, bool numbered, bool outmost) // reading a row int idx = p->nargs() - p->ncols(); for (int i = 0; i < col - 1; ++i, ++idx) - mathed_parse(p->cell(idx), FLAG_AMPERSAND); - mathed_parse(p->cell(idx), FLAG_NEWLINE | FLAG_END); + mathed_parse_into(p->cell(idx), FLAG_AMPERSAND); + mathed_parse_into(p->cell(idx), FLAG_NEWLINE | FLAG_END); if (outmost) { MathMatrixInset * m = static_cast(p); @@ -433,7 +433,7 @@ MathInset * mathed_parse() string arg = lexArg('['); int narg = arg.empty() ? 0 : atoi(arg.c_str()); p = new MathMacroTemplate(name, narg); - mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); + mathed_parse_into(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); //lyxerr[Debug::MATHED] << "LM_TK_NEWCOMMAND: name: " // << name << " nargs: " << narg << "\n"; break; @@ -454,7 +454,7 @@ MathInset * mathed_parse() case LM_OT_SIMPLE: { curr_num = latex_mathenv[i].numbered; curr_label = string(); - mathed_parse(m->cell(0), 0); + mathed_parse_into(m->cell(0), 0); m->numbered(0, curr_num); m->label(0, curr_label); break; @@ -463,7 +463,7 @@ MathInset * mathed_parse() case LM_OT_EQUATION: { curr_num = latex_mathenv[i].numbered; curr_label = string(); - mathed_parse(m->cell(0), FLAG_END); + mathed_parse_into(m->cell(0), FLAG_END); m->numbered(0, curr_num); m->label(0, curr_label); break; @@ -508,13 +508,13 @@ MathInset * mathed_parse() void handle_frac(MathArray & array, string const & name) { MathFracInset * p = new MathFracInset(name); - mathed_parse(p->cell(0), FLAG_ITEM); - mathed_parse(p->cell(1), FLAG_ITEM); + mathed_parse_into(p->cell(0), FLAG_ITEM); + mathed_parse_into(p->cell(1), FLAG_ITEM); array.push_back(p); } -void mathed_parse(MathArray & array, unsigned flags) +void mathed_parse_into(MathArray & array, unsigned flags) { static int plevel = -1; @@ -609,12 +609,12 @@ void mathed_parse(MathArray & array, unsigned flags) break; case '^': - mathed_parse( + mathed_parse_into( lastScriptInset(array, true, false, limits)->cell(0), FLAG_ITEM); break; case '_': - mathed_parse( + mathed_parse_into( lastScriptInset(array, false, true, limits)->cell(1), FLAG_ITEM); break; @@ -683,12 +683,12 @@ void mathed_parse(MathArray & array, unsigned flags) unsigned char c = getuchar(yyis); if (c == '[') { array.push_back(new MathRootInset); - mathed_parse(array.back_inset()->cell(0), FLAG_BRACK_END); - mathed_parse(array.back_inset()->cell(1), FLAG_ITEM); + mathed_parse_into(array.back_inset()->cell(0), FLAG_BRACK_END); + mathed_parse_into(array.back_inset()->cell(1), FLAG_ITEM); } else { yyis->putback(c); array.push_back(new MathSqrtInset); - mathed_parse(array.back_inset()->cell(0), FLAG_ITEM); + mathed_parse_into(array.back_inset()->cell(0), FLAG_ITEM); } break; } @@ -702,7 +702,7 @@ void mathed_parse(MathArray & array, unsigned flags) ld = yylval.i; MathArray ar; - mathed_parse(ar, FLAG_RIGHT); + mathed_parse_into(ar, FLAG_RIGHT); int rd = yylex(); if (rd == LM_TK_SYM) @@ -736,7 +736,7 @@ void mathed_parse(MathArray & array, unsigned flags) //MathArray tmp = array; //MathSizeInset * p = new MathSizeInset(MathStyles(yylval.l->id)); //array.push_back(p); - //mathed_parse(p->cell(0), FLAG_BRACE_FONT); + //mathed_parse_into(p->cell(0), FLAG_BRACE_FONT); break; } @@ -744,7 +744,7 @@ void mathed_parse(MathArray & array, unsigned flags) case LM_TK_DECORATION: { MathDecorationInset * p = new MathDecorationInset(yylval.l); - mathed_parse(p->cell(0), FLAG_ITEM); + mathed_parse_into(p->cell(0), FLAG_ITEM); array.push_back(p); break; } @@ -761,7 +761,7 @@ void mathed_parse(MathArray & array, unsigned flags) if (MathMacroTable::hasTemplate(yytext)) { MathMacro * m = MathMacroTable::cloneTemplate(yytext); for (int i = 0; i < m->nargs(); ++i) - mathed_parse(m->cell(i), FLAG_ITEM); + mathed_parse_into(m->cell(i), FLAG_ITEM); array.push_back(m); m->metrics(LM_ST_TEXT); } else @@ -838,7 +838,7 @@ MathArray mathed_parse_cell(string const & str) yyis = &is; yylineno = 0; MathArray ar; - mathed_parse(ar, 0); + mathed_parse_into(ar, 0); return ar; } -- 2.39.2