memory leaks in vfs_catia and vfs_cap modules ?

Jeremy Allison jra at samba.org
Thu Feb 12 13:14:31 MST 2009


On Thu, Feb 12, 2009 at 08:45:53PM +0100, Olivier Sessink wrote:
> Jeremy Allison wrote:
>> On Tue, Feb 10, 2009 at 09:35:26PM +0100, Olivier Sessink wrote:
>>> Hi all,
>>>
>>> while looking around in other code how to add a feature to the
>>> scannedonly samba vfs module I either found some memory leaks in
>>> vfs_catia and vfs_cap or I don't understand how samba manages the VFS
>>> module memory.
>>>
>>> Both vfs_catia and vfs_cap change the name of the files in their
>>> _readdir() implementations. Both VFS modules allocate a new
>>> SMB_STRUCT_DIRENT and return that to the caller. But both modules
>>> don't keep track of the allocated pointer, so how is this memory ever
>>> freed? The caller of the _readdir() function is not supposed to free
>>> the result, right?
>>>
>>> Can anyone shed some light on this issue? Is my understanding of the
>>> VFS module memory management wrong, or are there indeed memory leaks
>>> in these modules?
>>
>> Just looking at the vfs_catia module it uses TALLOC_ARRAY(talloc_tos(),
>> to allocate the new SMB_STRUCT_DIRENT. The talloc library keeps track
>> of the allocated pointer, and as soon as the talloc frame returned by
>> talloc_tos() is freed, (usually the calling function), then the memory
>> is freed.
>
> ahh thanks! so my understanding of the code was the issue :)
>
> I'll use the talloc function too then.

You need to make sure the talloc context you're allocing from
remains around long enough, but you're almost certainly safe
with talloc_tos() for a SMB_STRUCT_DIRENT return.

Jeremy.


More information about the samba-technical mailing list