summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2016-02-23 11:22:58 +0100
committerAndreas Schneider <asn@samba.org>2016-02-24 08:29:31 +0100
commit1f9ea967f81938a86fd120f59daaa01f055cdb48 (patch)
treef531fafc5c66121fff1303ce366a187f4a1ff8a3
parentad9e56e2b695cdba7000829c43d7c444a227fe4d (diff)
downloadsocket_wrapper-1f9ea967f81938a86fd120f59daaa01f055cdb48.tar.gz
socket_wrapper-1f9ea967f81938a86fd120f59daaa01f055cdb48.tar.xz
socket_wrapper-1f9ea967f81938a86fd120f59daaa01f055cdb48.zip
swrap: Use calloc() instead of malloc and memset
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--src/socket_wrapper.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a04a705..fc9116b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1855,11 +1855,10 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
alloc_len = SWRAP_PACKET_MIN_ALLOC;
}
- base = (uint8_t *)malloc(alloc_len);
+ base = (uint8_t *)calloc(1, alloc_len);
if (base == NULL) {
return NULL;
}
- memset(base, 0x0, alloc_len);
buf = base;
@@ -2436,8 +2435,7 @@ static int swrap_socket(int family, int type, int protocol)
swrap_remove_stale(fd);
}
- si = (struct socket_info *)malloc(sizeof(struct socket_info));
- memset(si, 0, sizeof(struct socket_info));
+ si = (struct socket_info *)calloc(1, sizeof(struct socket_info));
if (si == NULL) {
errno = ENOMEM;
return -1;
@@ -2631,8 +2629,12 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
return ret;
}
- child_si = (struct socket_info *)malloc(sizeof(struct socket_info));
- memset(child_si, 0, sizeof(struct socket_info));
+ child_si = (struct socket_info *)calloc(1, sizeof(struct socket_info));
+ if (child_si == NULL) {
+ close(fd);
+ errno = ENOMEM;
+ return -1;
+ }
child_fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd));
if (child_fi == NULL) {