Wed 21 Jun 2017 05:07:26 PM UTC, original submission:
In function lwip_netconn_do_gethostbyname we have:
API_EXPR_DEREF(msg->err) = dns_gethostbyname_addrtype(msg->name,
API_EXPR_REF(msg->addr), lwip_netconn_do_dns_found, msg,
exist path in call dns_gethostbyname_addrtype with call lwip_netconn_do_dns_found()[when dhcp is just start working].
Scenario:
1. call netconn_gethostbyname(),send messege (tcpcallback) to tcp_thread and wait on semaphore for result.
2. tcp_thread call lwip_netconn_do_gethostbyname
3. lwip_netconn_do_gethostbyname call dns_gethostbyname_addrtype
4. somewhere in dns_gethostbyname_addrtype call lwip_netconn_do_dns_found.
5. lwip_netconn_do_dns_found signal semaphore.
6. In another thread netconn_gethostbyname() can continue (semaphore is signaled), function netconn_gethostbyname()is finished (address msg and err is not valid, is somewere in the stack).
7. Assign msg->err in statement:
API_EXPR_DEREF(msg->err) = dns_gethostbyname_addrtype(msg->name,
API_EXPR_REF(msg->addr), lwip_netconn_do_dns_found, msg,
write somewere in memory on the stack.
8. My program crash (tcp_thread write on stack another thread).
Fast my bugfix in netconn_gethostbyname() is add:
{
int err1 = tcpip_callback(lwip_netconn_do_nothing, &API_VAR_REF(msg));
if (err1 == SOK) {
sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem));
}
}
after:
sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem));
or wait some ms after:
sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem));
|