Alan Coopersmith wrote:
> Doug Scott wrote:
>> Alan Coopersmith wrote:
>>>> Glynn Foster wrote:
>>>>> Gamin is currently built with a patch that should enable Solaris' FEM -
>>>>>
>>>>> http://src.opensolaris.org/source/xref/jds/spec-files/trunk/patches/gamin-01-all.diff
>>>>>
>>> It also seems to have a useless malloc that results in a memory leak:
>>>
>>> getpeerucred allocates and returns the ucred structure - you don't need
>>> to preallocate it.
>>>
>>>
>> Alan,
>> Below is a from 'man getpeerucred'. If the manual page is correct you
>> do not have to preallocate it as you say. Though it should not allocate
>> any new memory if the ucred structure has already been allocated.
>>
>> Doug
>>
>> When successful, getpeerucred() stores the pointer to a
>> freshly allocated ucred_t in the memory location pointed to
>> by the ucred argument if that memory location contains the
>> null pointer. If the memory location is non-null, it will
>> reuse the existing ucred_t.
>>
>
> Ah, I missed that it would use it - then I guess it's not a memory leak,
> but it just seems strange, since I've never seen that done in any of the
> other code that uses getpeerucred().
And I've been corrected again to point out that I was half right - because the
application explicitly mallocs the memory, it's leaked in the failure case,
since it does a "goto failed" right over the ucred_free(), where I believe no
memory would be allocated if you just left the allocation up to
getpeerucred(). Also, you should probably use free() if you're going to use
malloc(), to avoid mixing and matching memory allocators there (not likely,
but possible), though dropping the malloc() and keeping the ucred_free() seems
cleaner to me.
--
-Alan Coopersmith- alan.coopersmith at sun.com
Sun Microsystems, Inc. - X Window System Engineering