> On Dec 31, 2016, at 13:49, Pedro Giffuni <p...@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
signature.asc
Description: Message signed with OpenPGP using GPGMail