1 /** @file parser_memleak.cpp
3 * This small program exhibits the memory leak in the ginac_yylex().
6 * valgrind --leak-check=yes ./parser_memleak
10 * ulimit -v `expr 64 \* 1024` ./parser_memleak
14 * GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <ginac/ginac.h>
32 using namespace GiNaC;
38 int main(int argc, char** argv) {
39 const symbol x("x"), y("y");
41 // parser-generated symbol => memory leak.
42 static const char* str[] = { "x^2+2*x*y + cos(x)", "Li2(x/y) + log(y/x)" };
44 // depends on the amount of the available VM, compiler options, etc.
45 const unsigned N_max = 500000;
49 for (; N < N_max; N++) {
50 e = ex(str[N & 1], syms);
52 } catch (std::bad_alloc) {
53 cerr << "N = " << N << endl;