I've a 2-d array declared as such

lower_tri = (float **)malloc(sizeof(float *)*(dimention));
for(i =0; i < dimention; ++i)
	lower_tri[i] = (float *)malloc(sizeof(float)*(i+1));

So that it looks like...

However, it causes a segmentation fault when I try to de-allocate the array with


(only in unix, Windows works fine)

I've tried using a for loop to deallocate the array row by row, but just come up with more errors.

Any idea how to deallocate this array?

Re: Malloc-free error in Unix 80 80

the array has to be deallocated in the reverse order that it was allocated

for(i =0; i < dimention; ++i)

If you get seg fault with that then it means the program has been corrupted somewhere.

Re: Malloc-free error in Unix 80 80

I'm sure it has. You're having an out-of-bounds array access somewhere.
Have you run this with valgrind yet? It can discover invalid memory accesses in some cases.

Re: Malloc-free error in Unix 80 80

Why did you create two threads for the same problem??? See your other thread for solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.