by iio7 on 4/30/25, 8:17 PM with 3 comments
by musicale on 5/1/25, 2:11 AM
Prevent "technical" memory leaks while creating actual memory leaks.
Also what happens when saver is zero due to a failed malloc?
by jll29 on 4/30/25, 8:35 PM
The OP essentially models within the C program what the operating system/C runtime already does for the C program - that's why we don't _need_ to call free() if we don't want to, we can just leave main or call exit() and everything will be nicely cleaned up by the OS without taking extra measures (the ISO C standard and POSIX guarantee that).
> Even if no other references to the pointer exist in the program, the pointer has not leaked.
IMHO, this is a misunderstanding. I would still call this a memory leak, because the ordinary code (the actual code that requested the particular block) lost control of it. Furthermore, how do you realize whether a particular block in the list of allocated chunks can be freed or not? (And once you hypothetically added such a detection function, you're well on your way to implement what is called a mark-and-sweep garbage collector.)
by abstractspoon on 5/1/25, 2:42 AM