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