Added small program that exhibits the memory leak in the ginac_yylex() [Sheplyakov].
authorJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Wed, 21 Nov 2007 04:19:50 +0000 (04:19 +0000)
committerJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Wed, 21 Nov 2007 04:19:50 +0000 (04:19 +0000)
check/parser_memleak.cpp [new file with mode: 0644]

diff --git a/check/parser_memleak.cpp b/check/parser_memleak.cpp
new file mode 100644 (file)
index 0000000..ebc6ed9
--- /dev/null
@@ -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 <iostream>
+#include <stdexcept>
+#include <ginac/ginac.h>
+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;
+}