Alex Rivera | Logout

How do I free memory obtained by sbrk()?

Asked 2010-01-12T20:09:46.793
18

I have a custom allocator function which uses sbrk() to obtain memory. How do I release this memory when it's no longer needed?

Is there a function equivalent to free() for malloc() ?

or do I have to use brk() to set the end of the data segment ?

Edit
Report

1 Answer

2

Don't use brk and sbrk. It's pretty much impossible to know which library functions might call malloc, and could change over time, so even if your program works now, it might break when somebody upgrades libc. They were excluded from POSIX for a very good reason.

answered 2010-07-26T13:32:27.753

Your Answer