heap problem

Hi everbody,

I have problems to deallocate 2 vectors in a structure. At the beginning of a function I allocate memory for these vectors. Then I work with them (without change the inicial position of the pointer). That is:

allocate
call function that works with them
deallocate

In this point I get this error: HEAP corrupted windows has triggered a break point..." and the file dbgheap.c was opened.
In the output window I have this: "Heap block at 05251688 modified at 0528D6B4 past requested size of 3c024.

I can't see the error because I checked out the pointer before and after call the function and it's right.

Have you any ideas?

Thank you very much.

Radeberger
can you post the code?
ok, I will prepare it. I have a lot of code...I can't post all of them
Hi everybody,

UPDATE: this only happens in Debug mode. Release seems to work fine. Do you know why?

Thanks

Radeberger
yes you can post only a subset of your code..where you think is the problem..
Hi again,

That's the code to allocate:

//allocate

vector1 = (double *) malloc(sizeof(double)*(_FRAME * _MaxT));
vector2 = (double *) malloc(sizeof(double)*(_FRAME * _MaxT));

//do some stuff (like fourier transformation, etc)

deallocate

free(vector1);
free(vector2);

Can it be that I have problems with the projet properties? under 'code generation'->'runtime library' /MT,/MTd....what is the best option for my application (It's a multithread application). I think if I change this options I have the same error but the break point is triggered in other position in this file dbgheap.c ...(at the moment I'm working with /MT...)

Thanks in advance!
You're almost certainly writing off the end of one or both of your memory blocks.

It's not working fine in Release, it's just not reporting the error. The Debug allocator returns blocks of memory with guard bytes at each end, so an overwrite can be detected.

Are you sure that size of a double times size of a pointer is all that's required?
Hi,

The size is fixed when I allocate the vector, but How I know the size for the free operation?

You don't.

You ask the allocator for a memory block of some size. If it can, it gives a pointer to a block that big. When you're done with it you give it back by passing back the pointer.

You already know the size as you asked for it to begin with.

Topic archived. No new replies allowed.