]> www.ginac.de Git - ginac.git/blobdiff - ginac/parser/parser.cpp
Fixed memory leak.
[ginac.git] / ginac / parser / parser.cpp
index 6bfaf002c4ef68d3fe16df344f045aad0a0495e3..52f7e1df3454c9df01b5dc9f90511d4373260397 100644 (file)
@@ -66,8 +66,18 @@ ex parser::parse_identifier_expr()
                Parse_error_("no function \"" << name << "\" with " <<
                             args.size() << " arguments");
        }
-       ex ret = GiNaC::function((unsigned)reader->second, args);
-       return ret;
+       // dirty hack to distinguish between serial numbers of functions and real
+       // pointers.
+       GiNaC::function* f = NULL;
+       try {
+               f = new GiNaC::function(reinterpret_cast<unsigned>(reader->second), args);
+       }
+       catch ( std::runtime_error ) {
+               if ( f ) delete f;
+               ex ret = reader->second(args);
+               return ret;
+       }
+       return f->setflag(status_flags::dynallocated);
 }
 
 /// paren_expr:  '(' expression ')'