From: Martin Schwenke Date: Tue, 15 Aug 2023 00:43:57 +0000 (+1000) Subject: ctdb-common: Improve error handling X-Git-Tag: samba-4.17.11~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74d43dd395b0481d1c7588e80a0e5cb542e7124b;p=thirdparty%2Fsamba.git ctdb-common: Improve error handling Factor out a failure label, which will get more use in subsequent commits, and only set private_data when success is certain. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15451 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit d87041d8968e91db9d257445321b85693303f95e) --- diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index 06dc558eb22..3a7b6eb41de 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -988,7 +988,6 @@ int ctdb_sys_open_capture_socket(const char *iface, void **private_data) errbuf); return -1; } - *((pcap_t **)private_data) = pt; pcap_packet_type = pcap_datalink(pt); switch (pcap_packet_type) { @@ -1005,8 +1004,7 @@ int ctdb_sys_open_capture_socket(const char *iface, void **private_data) #endif /* DLT_LINUX_SLL2 */ default: DBG_ERR("Unknown pcap packet type %d\n", pcap_packet_type); - pcap_close(pt); - return -1; + goto fail; } fd = pcap_get_selectable_fd(pt); @@ -1014,7 +1012,12 @@ int ctdb_sys_open_capture_socket(const char *iface, void **private_data) t, fd); + *((pcap_t **)private_data) = pt; return fd; + +fail: + pcap_close(pt); + return -1; } int ctdb_sys_close_capture_socket(void *private_data)