svn commit: r310984 - head/lib/libc/net
Ngie Cooper (yaneurabeya)
yaneurabeya at gmail.com
Sat Dec 31 21:55:20 UTC 2016
> On Dec 31, 2016, at 13:49, Pedro Giffuni <pfg at FreeBSD.org> wrote:
>
>
>
> On 12/31/16 16:00, Ngie Cooper wrote:
>> Author: ngie
>> Date: Sat Dec 31 21:00:08 2016
>> New Revision: 310984
>> URL: https://svnweb.freebsd.org/changeset/base/310984
>>
>> Log:
>> Use calloc instead of malloc + memset(.., 0, ..)
>>
>> MFC after: 1 week
>>
>> Modified:
>> head/lib/libc/net/getaddrinfo.c
>>
>> Modified: head/lib/libc/net/getaddrinfo.c
>> ==============================================================================
>> --- head/lib/libc/net/getaddrinfo.c Sat Dec 31 19:59:31 2016 (r310983)
>> +++ head/lib/libc/net/getaddrinfo.c Sat Dec 31 21:00:08 2016 (r310984)
>> @@ -691,9 +691,8 @@ reorder(struct addrinfo *sentinel)
>> return(n);
>>
>> /* allocate a temporary array for sort and initialization of it. */
>> - if ((aio = malloc(sizeof(*aio) * n)) == NULL)
>> + if ((aio = calloc(1, sizeof(*aio) * n)) == NULL)
>> return(n); /* give up reordering */
>
> This should be calloc(n, sizeof(*aio)))
>
> FWIW, the other cases are not very useful.
> Generally, replacing any malloc(x) with a calloc(1, x) doesn't bring any advantage as it won't catch any overflow.
Yeah, that would have been better.
The goal was to reduce complexity. I found some memory leaks with valgrind with bsnmp* last night involving getaddrinfo that I’m trying to chase down, and I noticed these while “in the neighborhood”.
Thanks!
-Ngie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/svn-src-all/attachments/20161231/765e406a/attachment.sig>
More information about the svn-src-all
mailing list