Hi,

I am using ROOT::Math::IntegratorMultiDim for multi-dimensional integration, it is the GSLMCIntegrator. There is memory leak and it crashes after few run. My integration is like this:

## fun1

```
double fun1(const double *k, const double *para)
{
const double s = para[0];
double z = k[0];
double r = sqrt(s*s + z*z);
double it =1/(1.0 + exp(((r - 7.0)/0.5)));
return it;
}
```

## fun2: integration over fun1

```
double fun2(const double *k, const double *para)
{
double b = para[0];
double s = k[0];
double theta = k[1];
double rp2 = s*s + (b/2)*(b/2) - s*b*cos(theta);
double rt2 = s*s + (b/2)*(b/2) + s*b*cos(theta);
double xl[1] = {-20.0};
double xu[1] = {20.0};
double par[1];
ROOT::Math::IntegratorMultiDim *ig1 = new ROOT::Math::IntegratorMultiDim(ROOT::Math::IntegrationMultiDim::kVEGAS, 0, 0, 1000);
ROOT::Math::WrappedParamFunction<> wf1(&fun1, 1, 1);
ig1->SetFunction(wf1);
par[0] = sqrt(rp2);
wf1.SetParameters(par);
double Ta = ig1->Integral(xl, xu);
ROOT::Math::IntegratorMultiDim *ig2 = new ROOT::Math::IntegratorMultiDim(ROOT::Math::IntegrationMultiDim::kVEGAS, 0, 0, 1000);
ROOT::Math::WrappedParamFunction<> wf2(&fun1, 1, 1);
ig2->SetFunction(wf2);
par[0] = sqrt(rt2);
wf2.SetParameters(par);
double Tb = ig2->Integral(xl, xu);
delete ig1;
delete ig2;
ig1 = 0; ig2 = 0;
wf1 = 0; wf2 = 0;
double one = 197 * Ta * (1.0 - exp(-cross * Tb*197));
return s * fun;
}
```

## Final integration over fun2

```
double getResult(double b, int nIter = 600000)
{
double xl[2] = {0.0, 0.0};
double xu[2] = {20.0, 2.0*TMath::Pi()};
par[0] = b;
ROOT::Math::IntegratorMultiDim *ig = new ROOT::Math::IntegratorMultiDim(ROOT::Math::IntegrationMultiDim::kVEGAS, 0, 0, nIter);
ROOT::Math::WrappedParamFunction<> wf(&fun2, 2, 1);
ig->SetFunction(wf);
wf.SetParameters(par);
double val = ig->Integral(xl, xu);
delete ig;
ig = 0;
wf = 0;
return val;
}
```

However, It runs fine by just replacing the integrator with the plane GSL integrator.

Any idea where the memory is leaking?

Thanks.