summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2017-07-30 22:25:18 +0200
committerLinus Nordberg <linus@nordu.net>2017-08-01 18:19:13 +0200
commitdf6a455f3c11625320dd831b1e799cd0a5b28a21 (patch)
tree69704aec731593e3b76dc37e3679a48ce4533843
parent65094f8683f95b3fd47172166fe084a8dccdc4ff (diff)
Don't use 'out' if malloc fails.
coverity: 1449518
-rw-r--r--util.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/util.c b/util.c
index 7938310..1c4882f 100644
--- a/util.c
+++ b/util.c
@@ -57,17 +57,17 @@ struct sockaddr *addr_copy(struct sockaddr *in) {
switch (in->sa_family) {
case AF_INET:
out = malloc(sizeof(struct sockaddr_in));
- if (out) {
- memset(out, 0, sizeof(struct sockaddr_in));
- ((struct sockaddr_in *)out)->sin_addr = ((struct sockaddr_in *)in)->sin_addr;
- }
+ if (out == NULL)
+ return NULL;
+ memset(out, 0, sizeof(struct sockaddr_in));
+ ((struct sockaddr_in *)out)->sin_addr = ((struct sockaddr_in *)in)->sin_addr;
break;
case AF_INET6:
out = malloc(sizeof(struct sockaddr_in6));
- if (out) {
- memset(out, 0, sizeof(struct sockaddr_in6));
- ((struct sockaddr_in6 *)out)->sin6_addr = ((struct sockaddr_in6 *)in)->sin6_addr;
- }
+ if (out == NULL)
+ return NULL;
+ memset(out, 0, sizeof(struct sockaddr_in6));
+ ((struct sockaddr_in6 *)out)->sin6_addr = ((struct sockaddr_in6 *)in)->sin6_addr;
break;
}
out->sa_family = in->sa_family;