mirror of
https://github.com/espressif/esp-lwip.git
synced 2026-06-05 21:04:45 +00:00
api_msg: Add fail-safe error handling for semaphore allocation failure
2.1.3-esp: a1bd9e44 api_msg: Fix crash to fail-safe error if cannot get semaphore
This commit is contained in:
@@ -126,6 +126,9 @@ netconn_apimsg(tcpip_callback_fn fn, struct api_msg *apimsg)
|
||||
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
apimsg->op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
if (!sys_sem_valid(apimsg->op_completed_sem)) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
|
||||
err = tcpip_send_msg_wait_sem(fn, apimsg, LWIP_API_MSG_SEM(apimsg));
|
||||
@@ -1314,6 +1317,9 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr)
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
API_VAR_REF(msg).sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
if (!sys_sem_valid(API_VAR_REF(msg).sem)) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD*/
|
||||
err = sys_sem_new(API_EXPR_REF(API_VAR_REF(msg).sem), 0);
|
||||
if (err != ERR_OK) {
|
||||
|
||||
@@ -2068,6 +2068,10 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
|
||||
API_SELECT_CB_VAR_REF(select_cb).exceptset = exceptset;
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
API_SELECT_CB_VAR_REF(select_cb).sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
if (!sys_sem_valid(API_SELECT_CB_VAR_REF(select_cb).sem)) {
|
||||
set_errno(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
if (sys_sem_new(&API_SELECT_CB_VAR_REF(select_cb).sem, 0) != ERR_OK) {
|
||||
/* failed to create semaphore */
|
||||
@@ -2413,6 +2417,11 @@ lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
API_SELECT_CB_VAR_REF(select_cb).poll_nfds = nfds;
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
API_SELECT_CB_VAR_REF(select_cb).sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
if (!sys_sem_valid(API_SELECT_CB_VAR_REF(select_cb).sem)) {
|
||||
set_errno(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
if (sys_sem_new(&API_SELECT_CB_VAR_REF(select_cb).sem, 0) != ERR_OK) {
|
||||
/* failed to create semaphore */
|
||||
|
||||
Reference in New Issue
Block a user