]> www.ginac.de Git - ginac.git/commitdiff
power::eval(): fix several memory leaks
authorAlexei Sheplyakov <alexei.sheplyakov@gmail.com>
Sun, 22 Aug 2010 20:09:18 +0000 (23:09 +0300)
committerJens Vollinga <jensv@nikhef.nl>
Mon, 23 Aug 2010 13:11:58 +0000 (15:11 +0200)
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

index d24c969a2145d5a755d574c475a4ea57fd05d139..c6bf7b9770d2fa939eb242fef780f6aa84286dc5 100644 (file)
@@ -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),