Bug 15572 - MEMORY_LEAK.EX in /source4/torture/basic/misc.c
Summary: MEMORY_LEAK.EX in /source4/torture/basic/misc.c
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Winbind (show other bugs)
Version: 4.16.11
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
Depends on:
Reported: 2024-02-07 11:59 UTC by e.bykhanova@fobos-nt.ru
Modified: 2024-02-07 13:33 UTC (History)
0 users

See Also:

misc.c:80-85 (54.58 KB, image/png)
2024-02-07 11:59 UTC, e.bykhanova@fobos-nt.ru
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description e.bykhanova@fobos-nt.ru 2024-02-07 11:59:40 UTC
Created attachment 18241 [details]

The static analyzer has detected MEMORY_LEAK: dynamic memory, referenced by 'fname', is allocated at misc.c:80 by calling function 'asprintf' and lost at misc.c:84. 

Seems that it is necessary to add free(fname) at misc.c:80-85 just as it is done at misc.c:134. Because without free(fname) at misc.c:84 an early exit from the function may cause a leak of the memory.  

1) misc.c:80-85
2) misc.c:134

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

Author E. Bykhanova (e.bykhanova@fobos-nt.ru).
Comment 1 Volker Lendecke 2024-02-07 13:33:59 UTC
There are more places in this routine where we leak fname. For example the "break;" statement in line 91 also leads to a leak of that memory.

In general, smbtorture is not any code that is supposed to be long-running in production, this is really a one-off command. I don't see that we obviously leak in the for-loop and for me that would be enough.

If you really need to fix it for your compliance tests, I would recommend converting that routine to using talloc, see https://talloc.samba.org/talloc/doc/html/index.html. Happy to accept patches.