diff options
author | Linus Nordberg <linus@nordu.net> | 2017-07-30 22:25:18 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-07-30 22:25:18 +0200 |
commit | bf803f4aab7e40c35d197c36651e4cd8097819dd (patch) | |
tree | 88d866f520ea9616052de345111eb39e94470d6c | |
parent | 99758d2928588ad21742c2c767dba313173d1e8d (diff) |
Don't use 'out' if malloc fails.
coverity: 1449518
-rw-r--r-- | util.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -68,17 +68,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; |