Will this leak memory?
- From: "Joakim Hove" <joakim.hove@xxxxxxxxx>
- Date: 8 Mar 2007 04:06:32 -0800
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
.
- Follow-Ups:
- Re: Will this leak memory?
- From: Bill Pursell
- Re: Will this leak memory?
- From: Roland Pibinger
- Re: Will this leak memory?
- From: Richard Bos
- Re: Will this leak memory?
- From: Franchie
- Re: Will this leak memory?
- From: Duncan Muirhead
- Re: Will this leak memory?
- From: santosh
- Re: Will this leak memory?
- Prev by Date: Re: Syntax error on #define
- Next by Date: Re: Syntax error on #define
- Previous by thread: Syntax error on #define
- Next by thread: Re: Will this leak memory?
- Index(es):
Relevant Pages
|