J
Joakim Hove
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
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