R Garth Wood (rgwood@itactics.itactics.com)
Fri, 15 Jan 1999 18:23:47 -0500 (EST)
On Fri, 15 Jan 1999, Shane Wegner wrote:
> I have a few questions with Memory allocation under Linux and am hoping
> someone here has some experience with it. In particular malloc(2) and
> free(2) questions. In the following function, does s free itself?
>
> int test(void) {
> char *s;
> s = malloc(1024);
> return 0;
> }
Nope. malloc() wouldn't be of much use if it did.
>
> The reason I ask this is I am wondering if I have to free all my variables
> whenever I return out of a function. For example, when I use char *strstr
Yes, if you malloc the mem. if you have
void f()
{
int i;
}
you don't.
> in a function, is it necessary to free the result inorder to prevent a
> memory leak?
See example.
+-----------------------------------------------------------------------+
| R Garth Wood | ...cooler than you. |
| | |
| rgwood@itactics.com | |
This archive was generated by hypermail 2.0b3 on Fri 15 Jan 1999 - 15:07:40 PST