From cc94094751459129e1392a93dfa0264adac789a5 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Sun, 22 Aug 2010 23:09:18 +0300 Subject: [PATCH] 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. (cherry picked from commit 5f896fa7f59bbce727e4bba23df9c4bbdbb55c29) --- ginac/power.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ginac/power.cpp b/ginac/power.cpp index d24c969a..c6bf7b97 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), -- 2.44.0