]> www.ginac.de Git - ginac.git/blob - check/parser_memleak.cpp
Renamed files *.tcc and *.hpp to *.h.
[ginac.git] / check / parser_memleak.cpp
1 /**
2  * This small program exhibits the memory leak in the ginac_yylex().
3  * Run it as
4  *
5  * valgrind --leak-check=yes  ./parser_memleak
6  *
7  * or simply
8  *
9  * ulimit -v `expr 64 \* 1024` ./parser_memleak
10  */
11 #include <iostream>
12 #include <stdexcept>
13 #include <ginac/ginac.h>
14 using namespace std;
15 using namespace GiNaC;
16
17 int main(int argc, char** argv) {
18         const symbol x("x"), y("y");
19         const lst syms(x, y);
20         // parser-generated symbol => memory leak.
21         static const char* str[] = { "x^2+2*x*y + cos(x)", "Li2(x/y) + log(y/x)" };
22         
23         // depends on the amount of the available VM, compiler options, etc.
24         const unsigned N_max = 500000;
25         unsigned N=0;
26         ex e;
27         try {
28                 for (; N < N_max; N++) {
29                         e = ex(str[N & 1], syms);
30                 }
31         } catch (std::bad_alloc) {
32                 cerr << "N = " << N << endl;
33                 return 1;
34         }
35         return 0;
36 }