diff --git a/wpa_supplicant/ctrl_iface_zephyr.c b/wpa_supplicant/ctrl_iface_zephyr.c index 5e17860de..f4a0d6d76 100644 --- a/wpa_supplicant/ctrl_iface_zephyr.c +++ b/wpa_supplicant/ctrl_iface_zephyr.c @@ -126,8 +126,20 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx, size_t reply_len = 0; buf = os_zalloc(CTRL_IFACE_MAX_LEN + 1); - if (!buf) + if (!buf) { + /* Do a dummy read to drain the data from the socket */ + static unsigned char dummy[512]; + + /* This is expected in OOM conditions, so, do not spam the log */ + wpa_printf(MSG_DEBUG, "Failed to allocate memory for ctrl_iface receive buffer"); + + do { + res = recv(sock, dummy, sizeof(dummy), + MSG_TRUNC | MSG_DONTWAIT); + } while (res > 0); return; + } + res = recv(sock, buf, CTRL_IFACE_MAX_LEN, 0); if (res < 0) { wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",