From 86fe62b1f98e61167e0f1012ff078a2f1547458f Mon Sep 17 00:00:00 2001 From: Jens Vollinga Date: Wed, 21 Nov 2007 04:19:50 +0000 Subject: [PATCH] Added small program that exhibits the memory leak in the ginac_yylex() [Sheplyakov]. --- check/parser_memleak.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 check/parser_memleak.cpp diff --git a/check/parser_memleak.cpp b/check/parser_memleak.cpp new file mode 100644 index 00000000..ebc6ed9f --- /dev/null +++ b/check/parser_memleak.cpp @@ -0,0 +1,36 @@ +/** + * This small program exhibits the memory leak in the ginac_yylex(). + * Run it as + * + * valgrind --leak-check=yes ./parser_memleak + * + * or simply + * + * ulimit -v `expr 64 \* 1024` ./parser_memleak + */ +#include +#include +#include +using namespace std; +using namespace GiNaC; + +int main(int argc, char** argv) { + const symbol x("x"), y("y"); + const lst syms(x, y); + // parser-generated symbol => memory leak. + static const char* str[] = { "x2+2*x*y + cos(x)", "Li2(x/y) + log(y/x)" }; + + // depends on the amount of the available VM, compiler options, etc. + const unsigned N_max = 500000; + unsigned N=0; + ex e; + try { + for (; N < N_max; N++) { + e = ex(str[N & 1], syms); + } + } catch (std::bad_alloc) { + cerr << "N = " << N << endl; + return 1; + } + return 0; +} -- 2.44.0