diff options
author | Moritz Jodeit <moritz@cvs.openbsd.org> | 2006-04-16 19:28:37 +0000 |
---|---|---|
committer | Moritz Jodeit <moritz@cvs.openbsd.org> | 2006-04-16 19:28:37 +0000 |
commit | 62c05bba0345e8bc14822e5cac2ef233577c9606 (patch) | |
tree | 251417ab5f3172c943d1af808cfe16def7d0bc3f /usr.sbin/sasyncd | |
parent | a3b1994ac01afc7d81f1560f8df5d2a755cea20f (diff) |
cleanup error handling to avoid two memleaks. found and ok pat@
Diffstat (limited to 'usr.sbin/sasyncd')
-rw-r--r-- | usr.sbin/sasyncd/net.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/usr.sbin/sasyncd/net.c b/usr.sbin/sasyncd/net.c index 2cb0cee6339..21c9287ca45 100644 --- a/usr.sbin/sasyncd/net.c +++ b/usr.sbin/sasyncd/net.c @@ -1,4 +1,4 @@ -/* $OpenBSD: net.c,v 1.11 2006/01/26 09:53:46 moritz Exp $ */ +/* $OpenBSD: net.c,v 1.12 2006/04/16 19:28:36 moritz Exp $ */ /* * Copyright (c) 2005 Håkan Olsson. All rights reserved. @@ -165,7 +165,7 @@ net_setup_listeners(void) listeners = (int *)calloc(2, sizeof(int)); if (!listeners) { perror("net_setup_listeners: calloc()"); - return -1; + goto errout; } listeners[1] = -1; listeners[0] = net_add_listener(sa); @@ -184,7 +184,7 @@ net_setup_listeners(void) if (getifaddrs(&ifap) != 0) { perror("net_setup_listeners: getifaddrs()"); - return -1; + goto errout; } /* How many addresses matches? */ @@ -204,14 +204,14 @@ net_setup_listeners(void) if (!count) { log_msg(0, "net_setup_listeners: no listeners found for %s", cfgstate.listen_on); - return -1; + goto errout; } /* Allocate one extra slot and set to -1, marking end of array. */ listeners = (int *)calloc(count + 1, sizeof(int)); if (!listeners) { perror("net_setup_listeners: calloc()"); - return -1; + goto errout; } for (i = 0; i <= count; i++) listeners[i] = -1; @@ -261,9 +261,11 @@ net_setup_listeners(void) errout: if (ifap) freeifaddrs(ifap); - for (i = 0; listeners[i] != -1; i++) - close(listeners[i]); - free(listeners); + if (listeners) { + for (i = 0; listeners[i] != -1; i++) + close(listeners[i]); + free(listeners); + } return -1; } |