summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-08-13 21:37:31 +0200
committerThomas Haller <thaller@redhat.com>2020-08-17 15:15:17 +0200
commit4e0e002092c763e989613018b1eb1ed9972849be (patch)
treeed6b4c6f797a413ba4f914843ff7bf0c083acb44
parent08318a0bacac0e54cada71f413dfe12da0efcb02 (diff)
downloadNetworkManager-4e0e002092c763e989613018b1eb1ed9972849be.tar.gz
n-dhcp4/connection: avoid compiler warning in n_dhcp4_c_connection_connect() about fd_udp uninitialized
With LTO and optimizations enabled, we get a compiler warning about fd_udp not initialized: ../src/n-dhcp4-c-connection.c: In function ‘n_dhcp4_c_connection_connect’: ../src/n-dhcp4-c-connection.c:196:13: error: ‘fd_udp’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 196 | r = epoll_ctl(connection->fd_epoll, | ^ ../src/n-dhcp4-c-connection.c:185:16: note: ‘fd_udp’ was declared here 185 | int r, fd_udp; | ^ https://github.com/nettools/n-dhcp4/commit/6c6e9368989eae699448611fc82f41d50bd39dd9
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-c-connection.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-connection.c b/shared/n-dhcp4/src/n-dhcp4-c-connection.c
index 6becfb5087..3123525390 100644
--- a/shared/n-dhcp4/src/n-dhcp4-c-connection.c
+++ b/shared/n-dhcp4/src/n-dhcp4-c-connection.c
@@ -182,7 +182,8 @@ int n_dhcp4_c_connection_listen(NDhcp4CConnection *connection) {
int n_dhcp4_c_connection_connect(NDhcp4CConnection *connection,
const struct in_addr *client,
const struct in_addr *server) {
- int r, fd_udp;
+ _c_cleanup_(c_closep) int fd_udp = -1;
+ int r;
c_assert(connection->state == N_DHCP4_C_CONNECTION_STATE_PACKET);
@@ -200,27 +201,21 @@ int n_dhcp4_c_connection_connect(NDhcp4CConnection *connection,
.events = EPOLLIN,
.data = { .u32 = N_DHCP4_CLIENT_EPOLL_IO },
});
- if (r < 0) {
- r = -errno;
- goto exit_fd;
- }
+ if (r < 0)
+ return -errno;
r = packet_shutdown(connection->fd_packet);
- if (r < 0)
- goto exit_epoll;
+ if (r < 0) {
+ epoll_ctl(connection->fd_epoll, EPOLL_CTL_DEL, fd_udp, NULL);
+ return r;
+ }
connection->state = N_DHCP4_C_CONNECTION_STATE_DRAINING;
connection->fd_udp = fd_udp;
+ fd_udp = -1;
connection->client_ip = client->s_addr;
connection->server_ip = server->s_addr;
- fd_udp = -1;
return 0;
-
-exit_epoll:
- epoll_ctl(connection->fd_epoll, EPOLL_CTL_DEL, fd_udp, NULL);
-exit_fd:
- close(fd_udp);
- return r;
}
void n_dhcp4_c_connection_close(NDhcp4CConnection *connection) {