Hi,
Thank you for answer, this code was only a simplified example of my code,
there are some synchronisation mechanisms used in application, I removed
them to clarify my question. I will recheck them again.
My message was only part of description of my problem, read full story
in another email.
-- 
Szymon

2013/1/14 Sylvain Rochet <grada...@gradator.net>

> 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
>
> _______________________________________________
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to