Re: will I get Memory leak..



gNash wrote:

Could you any one please tell me how is free() is working?

If passed a pointer to a piece of memory which was allocated with
malloc(), calloc() or realloc(), which has not already been freed by a
call to free() or realloc, free() returns that memory to the pool which
malloc() etc allocate from.

if passed a NULL pointer, free() does nothing.

If passed any other pointer, the behaviour is undefined.

If you want to know how free() accomplishes this, you are asking about
the implementation details, which differ - you'd have to refer to the
source code for a specific malloc()/calloc()/realloc()/free()
implementation.
.



Relevant Pages

  • Re: Extra bytes
    ... malloc, assigning a new block of size bytes and returning a pointer to ... "The realloc function changes the size of an allocated memory block. ... The memblock argument points to the beginning of the memory block. ...
    (comp.unix.programmer)
  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... Bill Reid wrote in message ... If block is a NULL pointer, realloc works just like malloc. ...
    (comp.lang.c)
  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... I believe I actually do call malloc() in some xxx.cpp files... ... What you quoted above is not *the* documentation for qsort. ... If block is a NULL pointer, realloc works just like malloc. ...
    (comp.lang.c)
  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... I believe I actually do call malloc() in some xxx.cpp files... ... If block is a NULL pointer, realloc works just like malloc. ... I can use realloc in a loop and the first pass ...
    (comp.lang.c)
  • Re: Question about the *= (and similar) operator
    ... always return a pointer to fresh storage. ... calling realloc. ... Assume malloc works and then realloc fails. ... We'll have ptr set to NULL and no reference to the memory malloc gave us. ...
    (comp.lang.c)