Re: trouble in freeing memory using realloc





cijo wrote:
> Hi,
>
> My program has a pointer to a structure declared locally inside a
> function to which memory is allocated using malloc and reallocated
> later using realloc, and when I try to free the memory at the end of
> the function, the program breaks down. While debugging, I find that the
> address to which the pointer is pointing is changed during one of the
> realloc calls. But as per the documentation on realloc, the change of
> address is perfectly normal. Some of my colleagues say the failure in
> 'free'ing the memory is due to some bug in 'realloc'. I find it hard to
> believe though. Is it dependent on the compiler (the IDE is MS Visual
> Studion .NET 2003) or could there be something wrong with my code?

There could be something wrong with your code.

Try distilling the problem down to a short but complete
and compilable example that shows the trouble, and post
that example. It is astonishing how much better my crystal
ball works when I don't need to consult it ...

--
Eric.Sosman@xxxxxxx

.



Relevant Pages

  • Re: Mex Overflow Error Using Free Borland Compiler
    ... >>>in the Borland compiler. ... > handles memory questions, so I prefer to use the C functions I know. ... >>1- You declare the variables of type double and allocate of size long double. ... You'll get exceptions a lot quicker dereferncing a NULL pointer than a "wild ...
    (comp.soft-sys.matlab)
  • Re: Mex Overflow Error Using Free Borland Compiler
    ... >>Borland compiler handles overflow errors. ... >>The first thing I tried is dynamic memory allocation. ... 1- You declare the variables of type double and allocate of size long double. ... would clean up a lot of code by eliminating the pointer dereferences. ...
    (comp.soft-sys.matlab)
  • Re: OT: Requesting C advice
    ... some behind the scenes action of the compiler. ... In fact the memory could ... Proper initialization means that floats and doubles must be initialized to 0.0 and pointers must be initialized to the null pointer value, even if those bit patterns differ from all-bits-zero. ...
    (Fedora)
  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... If your compiler ... it works with a cast. ... Pointer arithmetic, as you probably know, is scaled by ... not sure about concerning realloc(). ...
    (comp.lang.c)
  • Re: Mex Overflow Error Using Free Borland Compiler
    ... >>>Borland compiler handles overflow errors. ... >>>The first thing I tried is dynamic memory allocation. ... > 1- You declare the variables of type double and allocate of size long double. ... > would clean up a lot of code by eliminating the pointer dereferences. ...
    (comp.soft-sys.matlab)