2 * @file mul_eval_memleak.cpp Test for memory leak in {mul,power}::eval
4 * The bug was introduced by
6 * commit f418c6ee4d558c852e1fb95533af07a3ae43f409
7 * Author: Alexei Sheplyakov <varg@theor.jinr.ru>
8 * Date: Wed Jul 11 14:34:42 2007 +0400
9 * (it was commited into the official branch as
10 * commit a602d34c225dceb3e53742a7b3e19a4b5e280485
11 * Author: Jens Vollinga <vollinga@thep.physik.uni-mainz.de>
12 * Date: Wed Jul 11 21:07:40 2007 +0000)
16 * GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <ginac/ginac.h>
38 using namespace GiNaC;
40 const unsigned check_mul_eval_memleak(const unsigned N)
42 // Expanding this expression into a Laurent series triggers the bug.
43 static const string e_str("\
44 1/605927415293858601*tgamma(3-eps)^(-1)*tgamma(2-eps)*(5013234896802\
45 *(-1+2*eps)*((-2539001/2)*eps^(-2)+(-7617003/2+1692800*log(920*scale\
46 ^(-1))+3385202*log(1301*scale^(-1)))*eps^(-1)+F)+(846400+2539001*eps\
47 )*(2539001*(-1+2*eps)*((-2539001/2)*eps^(-2)+(-7617003/2+1692800*log\
48 (920*scale^(-1))+3385202*log(1301*scale^(-1)))*eps^(-1)+F)+286523497\
49 2800*(-1+eps)^(-1)*eps^(-2)*(920*scale^(-1))^(-2*eps)*(1301*scale^(-\
50 1))^(-2*eps)*tgamma(1+eps)^2)+6061411748045832000*(-1+eps)^(-1)*eps^\
51 (-2)*(920*scale^(-1))^(-2*eps)*(1301*scale^(-1))^(-2*eps)*tgamma(1+e\
52 ps)^2+716056132401*((-2539001/2)*eps^(-2)+(-7617003/2+1692800*log(92\
53 0*scale^(-1))+3385202*log(1301*scale^(-1)))*eps^(-1)+F))+71656139360\
54 0/716056132401*tgamma(1-eps)*tgamma(2*eps)^(-1)*tgamma(eps)^2*tgamma\
55 (3-eps)^(-1)*(920*scale^(-1))^(-4*eps)*tgamma(-1+2*eps)-2/6059274152\
56 93858601*tgamma(3-eps)^(-1)*(2149010446400*(-1+2*eps)*((-2539001/2)*\
57 eps^(-2)+(-7617003/2+1692800*log(920*scale^(-1))+3385202*log(1301*sc\
58 ale^(-1)))*eps^(-1)+F)+2425134880977920000*(-1+eps)^(-1)*eps^(-2)*(9\
59 20*scale^(-1))^(-2*eps)*(1301*scale^(-1))^(-2*eps)*tgamma(1+eps)^2-7\
60 16056132401*((-2539001/2)*eps^(-2)+(-7617003/2+1692800*log(920*scale\
61 ^(-1))+3385202*log(1301*scale^(-1)))*eps^(-1)+F)+1692601*(-1+2*eps)*\
62 (2539001*(-1+2*eps)*((-2539001/2)*eps^(-2)+(-7617003/2+1692800*log(9\
63 20*scale^(-1))+3385202*log(1301*scale^(-1)))*eps^(-1)+F)+28652349728\
64 00*(-1+eps)^(-1)*eps^(-2)*(920*scale^(-1))^(-2*eps)*(1301*scale^(-1)\
65 )^(-2*eps)*tgamma(1+eps)^2))*tgamma(2-eps)+(1/716056132401*I)*tgamma\
66 (-1+eps)*mb^2*(mb*scale^(-1))^(-2*eps)*((716392960000*I)*mb^(-2)*(92\
67 0*scale^(-1))^(-2*eps)*tgamma(-2+eps)-(2864898145201*I)*mb^(-2)*(130\
68 1*scale^(-1))^(-2*eps)*tgamma(-2+eps)-(716224526400*I)*tgamma(-1+eps\
69 )*mb^(-2)*(920*scale^(-1))^(-2*eps))-3385202/605927415293858601*tgam\
70 ma(3-eps)^(-1)*tgamma(2-eps)*(2539001*(-1+2*eps)*((-2539001/2)*eps^(\
71 -2)+(-7617003/2+1692800*log(920*scale^(-1))+3385202*log(1301*scale^(\
72 -1)))*eps^(-1)+F)+2865234972800*(-1+eps)^(-1)*eps^(-2)*(920*scale^(-\
73 1))^(-2*eps)*(1301*scale^(-1))^(-2*eps)*tgamma(1+eps)^2+846201*((-25\
74 39001/2)*eps^(-2)+(-7617003/2+1692800*log(920*scale^(-1))+3385202*lo\
75 g(1301*scale^(-1)))*eps^(-1)+F))\
77 const symbol eps("eps"), scale("scale"), mb("mb"), F("F");
78 const lst syms(eps, scale, mb, F);
79 const ex e0(e_str, syms);
82 unsigned n_failures = 0;
87 e = e0.series(eps, 1).subs(Euler==0).expand();
88 } catch (std::bad_alloc) {
94 #include <sys/types.h>
96 #include <sys/resource.h>
99 static void set_VM_limit(const unsigned long MB) {
100 const unsigned mem_lim_kb = MB*1024*1024;
102 lim.rlim_cur = mem_lim_kb;
103 lim.rlim_max = mem_lim_kb;
104 setrlimit(RLIMIT_AS, &lim);
107 int main(int argc, char** argv) {
108 static const unsigned max_mem = 32; // megabytes
109 // otherwise one need wait for a long[er] time.
110 set_VM_limit(max_mem);
111 static const unsigned n_of_tests = 10000;
112 const unsigned n_loops = check_mul_eval_memleak(n_of_tests);
114 cerr << "memory exhausted after " << n_loops << " loops" << endl;