[PATCH] [bugfix] power::eval(): fix several memory leaks
While working on fsolve bug I've noticed the following in valgrind log: ==17455== 136 (56 direct, 80 indirect) bytes in 1 blocks are definitely lost in loss record 16 of 19 ==17455== at 0x4C249C7: operator new(unsigned long) (vg_replace_malloc.c:220) ==17455== by 0x516CA70: GiNaC::power::eval(int) const (power.cpp:540) ==17455== by 0x4FC1E39: GiNaC::ex::construct_from_basic(GiNaC::basic const&) (ex.cpp:310) ==17455== by 0x406FBF: main (ex.h:255) Heap allocated objects definitely need the status_flags::dyncallocated flag. --- ginac/power.cpp | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/ginac/power.cpp b/ginac/power.cpp index d24c969..c6bf7b9 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -539,6 +539,7 @@ ex power::eval(int level) const if (num_coeff.is_positive()) { mul *mulp = new mul(mulref); mulp->overall_coeff = _ex1; + mulp->setflag(status_flags::dynallocated); mulp->clearflag(status_flags::evaluated); mulp->clearflag(status_flags::hash_calculated); return (new mul(power(*mulp,exponent), @@ -548,6 +549,7 @@ ex power::eval(int level) const if (!num_coeff.is_equal(*_num_1_p)) { mul *mulp = new mul(mulref); mulp->overall_coeff = _ex_1; + mulp->setflag(status_flags::dynallocated); mulp->clearflag(status_flags::evaluated); mulp->clearflag(status_flags::hash_calculated); return (new mul(power(*mulp,exponent), -- 1.7.1
participants (1)
-
Alexei Sheplyakov