Will this leak memory?



Hello,

I have the following code:

foo_ptr * alloc_foo(int size, ...) {
/*
This function allocates an instance of the foo_ptr type,
and returns a pointer to the newly allocated storage.
*/
}

void free_foo(foo_ptr *foo) {
....
}

void func(const foo_ptr *foo) {
/*
Do something (read-only) on the foo object.
*/
}


int main(void) {

func( alloc_foo(10 , ...) );

}

Now my question is wether the memory set aside by alloc_foo() will
leak. Since I have not stored a pointer to this memory I can not free
it myself. If this will indeed leak memory I will have to do it like
this:

{
foo_ptr *tmp_foo = foo_alloc(10 , ...);
func(tmp_foo);
free_foo(tmp_foo);
}

Which is considerably less elegant.

Best regards

Joakim

.



Relevant Pages

  • Re: Differance between Array and Pointers
    ... a pointer is a variable in memory that contains the address of ... to load it from memory into a register, then use it to load the ... An array is the big chunk of memory itself. ... foo dw OFFSET str ...
    (comp.arch.embedded)
  • Re: Will this leak memory?
    ... This function allocates an instance of the foo_ptr type, ... void func(const foo_ptr *foo) { ... Since I have not stored a pointer to this memory I can not free ... As it stands, this will leak memory, as you never free it. ...
    (comp.lang.c)
  • Re: DRAM data persistence
    ... Any modern OS clears the memory before freeing it for use ... This function returns a pointer to a newly allocated block SIZE ... This function allocates a block long enough to contain a vector of ...
    (sci.electronics.design)
  • Re: Is this math test too easy?
    ... > communications glitch; one of the more laughable cartoons ... it was loaded into physical memory and, ... > Or one can interpret the character string as one of the values ... A pointer to an integer? ...
    (sci.math)
  • Re: grow list by tail, pointer example recipe -- please comment
    ... manufacturing a pointer with that address. ... the next cons cell. ... believe these lists are in consecutive memory locations. ...
    (comp.lang.lisp)