]> www.ginac.de Git - ginac.git/commitdiff
fixed memory leak in subs(), reproducible by, for example, the following code:
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 26 Aug 2003 19:37:55 +0000 (19:37 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 26 Aug 2003 19:37:55 +0000 (19:37 +0000)
    symbol x("x");
    ex e = lst(x, 1/x);
    ex f = e.subs(x == 0); // throws an exception

ginac/container.pl
ginac/expairseq.cpp

index 83fdc66715c01ed5525b892f8f3dfe8ac04fb01e..9d77d540b5bbe194fc934d992d7d60466960c51e 100755 (executable)
@@ -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;
index df270bdc3c4dc883eb63b297b4a2eaa1b44e9448..49bd5e7469b9835a5ecb00a55362f3738b8cb97e 100644 (file)
@@ -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;