On Sun, Sep 22, 2024 at 08:07:54PM +0200, Страхиња Радић wrote:
> Дана 24/09/22 07:59PM, Страхиња Радић написа: > > 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. > > Correction/clarification: even if the result is discarded, this still > causes the leak, just the pointer to the allocated memory is not > assigned to a variable. This is easily verifiable by using > ktrace(1)/kdump(1). > All correct, but still, on process exit all resources used by a program are cleaned up. In that sense it is not a memory leak to not call free. Especially for one-time allocations. It is differrent if the malloc is e.g. in a loop, causing memory usage to grow while executing the program. That is a memory leak you want to fix, especially if the program is a long running one, like a daemon. -Otto