Hi Szymon,

On Mon, Jan 14, 2013 at 03:25:22PM +0100, Szymon Tarnowski wrote:
> Hi,
> I am developing a commercial application for embedded device using lwip.
> My device is listening on specific tcp port for incomming message, if client
> connects can send request and get response then decide if want to keep
> connection or disconnect. My device is based on AVR32 processor, and
> under this device application is working correct. As a part of my quality
> assurance test I must recompile this application under linux and test
> memory leaks and stability. Under valgrind I receive some exceptions
> about invalid memory reads deep inside lwip, then application crash with
> exception segmentation fault. Inside my application I have such code:
> (listening task)
> if (netconn_acept(listening_conn, &new_conn) == ERR_OK)
> {
>  add_new_client(new_conn)
> }
> (client support task)
> for (i=0; i<clients; i++)
> {
> if client_wants_close
> 
> }

This is probably not thread safe, I guess add_new_client() change the 
clients value, which might be changed as well with your 
client_wants_close. This is probably not the segfault cause, but you 
must lock using a mutex or a critical section the "clients" value. Like 
this pattern:

mutex_lock(clients_lock);
clients++;
mutex_unlock(clients_lock);

mutex_lock(clients_lock);
clients--;
mutex_unlock(clients_lock);

mutex_lock(clients_lock);
for(i=0; i<clients; i++) {
  ...
}
mutex_unlock(clients_lock);

Sylvain

Attachment: signature.asc
Description: Digital signature

_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to