Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jan 2017 08:17:18 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r311382 - head/contrib/bsnmp/snmpd
Message-ID:  <201701050817.v058HIiK069442@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Thu Jan  5 08:17:17 2017
New Revision: 311382
URL: https://svnweb.freebsd.org/changeset/base/311382

Log:
  Use calloc instead of malloc + memset(.., 0, ..)
  
  MFC after:	3 days

Modified:
  head/contrib/bsnmp/snmpd/trans_lsock.c

Modified: head/contrib/bsnmp/snmpd/trans_lsock.c
==============================================================================
--- head/contrib/bsnmp/snmpd/trans_lsock.c	Thu Jan  5 08:14:20 2017	(r311381)
+++ head/contrib/bsnmp/snmpd/trans_lsock.c	Thu Jan  5 08:17:17 2017	(r311382)
@@ -146,16 +146,14 @@ lsock_open_port(u_char *name, size_t nam
 		return (SNMP_ERR_BADVALUE);
 	}
 
-	if ((port = malloc(sizeof(*port))) == NULL)
+	if ((port = calloc(1, sizeof(*port))) == NULL)
 		return (SNMP_ERR_GENERR);
 
-	memset(port, 0, sizeof(*port));
 	if (!is_stream) {
-		if ((peer = malloc(sizeof(*peer))) == NULL) {
+		if ((peer = calloc(1, sizeof(*peer))) == NULL) {
 			free(port);
 			return (SNMP_ERR_GENERR);
 		}
-		memset(peer, 0, sizeof(*peer));
 	}
 	if ((port->name = malloc(namelen + 1)) == NULL) {
 		free(port);
@@ -261,12 +259,11 @@ lsock_listen_input(int fd, void *udata)
 	struct lsock_port *p = udata;
 	struct lsock_peer *peer;
 
-	if ((peer = malloc(sizeof(*peer))) == NULL) {
+	if ((peer = calloc(1, sizeof(*peer))) == NULL) {
 		syslog(LOG_WARNING, "%s: peer malloc failed", p->name);
 		(void)close(accept(fd, NULL, NULL));
 		return;
 	}
-	memset(peer, 0, sizeof(*peer));
 
 	peer->port = p;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701050817.v058HIiK069442>