From 46f5f27e60e950d5843382121238dabd487b143c Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Tue, 26 Aug 2003 19:37:55 +0000 Subject: [PATCH] fixed memory leak in subs(), reproducible by, for example, the following code: symbol x("x"); ex e = lst(x, 1/x); ex f = e.subs(x == 0); // throws an exception --- ginac/container.pl | 7 ++++++- ginac/expairseq.cpp | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ginac/container.pl b/ginac/container.pl index 83fdc667..9d77d540 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -700,7 +700,12 @@ ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr, unsigned op // copy rest while (cit2 != end) { - s->push_back(cit2->subs(ls, lr, options)); + try { + s->push_back(cit2->subs(ls, lr, options)); + } catch (...) { + delete s; + throw; + } ++cit2; } return s; diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index df270bdc..49bd5e74 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -1536,6 +1536,7 @@ epvector * expairseq::evalchildren(int level) const s->push_back(*cit2); ++cit2; } + // copy first changed element s->push_back(combine_ex_with_coeff_to_pair(evaled_ex, cit2->coeff)); @@ -1603,7 +1604,12 @@ epvector * expairseq::subschildren(const lst &ls, const lst &lr, unsigned option // Copy rest while (cit != last) { - s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit).subs(ls, lr, options))); + try { + s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit).subs(ls, lr, options))); + } catch (...) { + delete s; + throw; + } ++cit; } return s; @@ -1634,8 +1640,13 @@ epvector * expairseq::subschildren(const lst &ls, const lst &lr, unsigned option // Copy rest while (cit != last) { - s->push_back(combine_ex_with_coeff_to_pair(cit->rest.subs(ls, lr, options), - cit->coeff)); + try { + s->push_back(combine_ex_with_coeff_to_pair(cit->rest.subs(ls, lr, options), + cit->coeff)); + } catch (...) { + delete s; + throw; + } ++cit; } return s; -- 2.49.0