lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Closing netconn, application or lwip bug?


From: Sylvain Rochet
Subject: Re: [lwip-users] Closing netconn, application or lwip bug?
Date: Mon, 14 Jan 2013 15:32:06 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]