Improves:
ebbca8529732 ("commands_utils: fix socket leak when adding state client")
Cc: Matthias Hardt <matthias.hardt@gmail.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
if (ret < 0)
goto reap_client_fd;
- /* close fd if state is already achieved to avoid leakage */
- if (rsp.ret != MAX_STATE)
- close(fd);
-
return 0;
reap_client_fd:
close(client->clientfd);
free(cur->elem);
free(cur);
- /* No need to walk the whole list. If we found the state
+ /*
+ * No need to walk the whole list. If we found the state
* client fd there can't be a second one.
*/
break;
}
- break;
+
+ /*
+ * We didn't add the state client to the list. Either because
+ * we failed to allocate memory (unlikely) or because the state
+ * was already reached by the time we were ready to add it. So
+ * fallthrough and clean it up.
+ */
+ __fallthrough;
default:
close(fd);
}