2 * This small program exhibits the memory leak in the ginac_yylex().
5 * valgrind --leak-check=yes ./parser_memleak
9 * ulimit -v `expr 64 \* 1024` ./parser_memleak
13 #include <ginac/ginac.h>
15 using namespace GiNaC;
17 int main(int argc, char** argv) {
18 const symbol x("x"), y("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)" };
23 // depends on the amount of the available VM, compiler options, etc.
24 const unsigned N_max = 500000;
28 for (; N < N_max; N++) {
29 e = ex(str[N & 1], syms);
31 } catch (std::bad_alloc) {
32 cerr << "N = " << N << endl;