delete array allocated in a function

Hello, I have a deallocation problem :
I have several classes, and in one of these, a function is returning an array of double :
1
2
3
4
5
6
7
8
9
10
double *funtion()
{
double *a = new double[4];
a[0] = 1.
a[1] = 1.
a[2] = 1.
a[3] = 1.

return a;
}


An other function is calling the first one and uses the created array :

1
2
3
4
5
6
void function2()
{
double *b = function();

std::cout << b[0] << std::endl;
}


It seems to me that there is a memory leak there as I don't delete[] b in the end of function2, but when I try to do so I get an error message at runtime.
double post
Topic archived. No new replies allowed.