Sunday, September 22, 2024

Re: Need some information about fork(2)

Дана 24/09/22 07:57PM, Страхиња Радић написа:
> Дана 24/09/22 07:20PM, bilal@iscarioth.org написа:
> > malloc(13);/* <--- what will happen, a leak, it
> > will be freed ? */
>
> That will cause a memory leak. Every successful allocation needs to
> have a corresponding call to free(3).

Of course, that would cause a memory leak if the memory was assigned to
a variable, like this:

char* tmp = malloc(13);

otherwise, like this:

malloc(13);

the result is discarded and a warning is printed if the program is
compiled by GCC.

No comments:

Post a Comment