From 49146ab381f03036ad7fa5c2343be1a9335205a8 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 4 Jun 2018 23:06:37 -0700 Subject: [PATCH] ws: make retry logic in ws_get_protocol_catalog() more readable --- src/ws.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/ws.c b/src/ws.c index af88ec7..6c67740 100644 --- a/src/ws.c +++ b/src/ws.c @@ -49,22 +49,21 @@ int ws_get_protocol_catalog(WSAPROTOCOL_INFOW** infos_out, int count; WSAPROTOCOL_INFOW* infos; - for (;;) { - infos = malloc(buffer_size); - if (infos == NULL) - return_set_error(-1, ERROR_NOT_ENOUGH_MEMORY); +retry: + infos = malloc(buffer_size); + if (infos == NULL) + return_set_error(-1, ERROR_NOT_ENOUGH_MEMORY); - count = WSAEnumProtocolsW(NULL, infos, &buffer_size); - if (count == SOCKET_ERROR) { - free(infos); - if (WSAGetLastError() == WSAENOBUFS) - continue; /* Try again with bigger buffer size. */ - else - return_map_error(-1); - } - - *infos_out = infos; - *infos_count_out = (size_t) count; - return 0; + count = WSAEnumProtocolsW(NULL, infos, &buffer_size); + if (count == SOCKET_ERROR) { + free(infos); + if (WSAGetLastError() == WSAENOBUFS) + goto retry; /* Try again with bigger buffer size. */ + else + return_map_error(-1); } + + *infos_out = infos; + *infos_count_out = (size_t) count; + return 0; }