Se me hizo muy feliz la noche al aprender la opcion de -g al compilar.

Como bien dijiste, Gonzalo, el error estaba en hacer un join() de algo invalido.

El problema ahora es que en mi aplicacion Server_main.cpp, yo tengo lo 
siguiente:
-------
    Server s(puerto,max_clientes);
    s.run();
    s.join();
-------

El tema es que el destructor del Thread tenia un join(). Al ser server un 
thread, se llamaba 2 veces al join.
La duda es la siguiente: saco el join del main, o sino saco el join de Thread, 
y llamo a join de cada thread "afuera"??
Ya probe la 2da opcion, y no tengo mas el error que postee primeramente.

Igualmente, tengo un error igualmente, que me viene molestando desde que inicie 
el desarrollo:

[EMAIL PROTECTED]:~/Taller/TP4$ valgrind --leak-check=full ./server 10091 6
==29537== Memcheck, a memory error detector.
==29537== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==29537== Using LibVEX rev 1471, a library for dynamic binary translation.
==29537== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==29537== Using valgrind-3.1.0-Debian, a dynamic binary instrumentation 
framework.
==29537== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==29537== For more details, rerun with: -v
==29537==
==29537==
==29537== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 1)
==29537== malloc/free: in use at exit: 544 bytes in 4 blocks.
==29537== malloc/free: 233 allocs, 229 frees, 7,061 bytes allocated.
==29537== For counts of detected errors, rerun with: -v
==29537== searching for pointers to 4 not-freed blocks.
==29537== checked 33,846,040 bytes.
==29537==
==29537== 544 bytes in 4 blocks are possibly lost in loss record 1 of 1
==29537==    at 0x4A1AD7D: calloc (vg_replace_malloc.c:279)
==29537==    by 0x400DCA8: _dl_allocate_tls (in /lib/ld-2.3.6.so)
==29537==    by 0x4B246B8: pthread_create@@GLIBC_2.2.5 (in 
/lib/libpthread-2.3.6.so)
==29537==    by 0x4059B6: Thread::run() (common_Thread.cpp:17)
==29537==    by 0x4039C2: Server::main() (server_Server.cpp:41)
==29537==    by 0x405899: Thread::static_run(void*) (common_Thread.cpp:47)
==29537==    by 0x4B240F9: start_thread (in /lib/libpthread-2.3.6.so)
==29537==    by 0x5189CE1: clone (in /lib/libc-2.3.6.so)
==29537==
==29537== LEAK SUMMARY:
==29537==    definitely lost: 0 bytes in 0 blocks.
==29537==      possibly lost: 544 bytes in 4 blocks.
==29537==    still reachable: 0 bytes in 0 blocks.
==29537==         suppressed: 0 bytes in 0 blocks.
==29537== Reachable blocks (those to which a pointer was found) are not shown.
==29537== To see them, rerun with: --show-reachable=yes


----------------

En Server_server.cpp:
linea 38: ClientHandler* cliente = new ClientHandler(s);
linea 39: manejadores.push_back(cliente);

linea 41: cliente->run();


y en common_Thread.cpp:
linea 17: runed = !(bool)pthread_create(&th,NULL,static_run,(void*)this);


-----------------

Es mas, si yo lanzo un cliente, sin estar el server corriendo, pierde un bloque 
de memoria, con el mismo error ultimo que postee, y marca el error en la linea 
17 de common_thread.cpp, como en el caso anterior.


Que puede ser este ultimo error ???????


Muchas gracias por la respuesta anterior. Me trajo mucha felicidad al dia.
Suerte
Pablo Statile




----- Mensaje original -----
De: Gonzalo Merayo <[EMAIL PROTECTED]>
Fecha: Domingo, Mayo 13, 2007 8:45 pm
Asunto: Re: [Prog] Perdida de memoria en Thread en una situacion rara

> Pablo,
>    El problema no es la perdida de memoria, eso es consecuencia de:
> Invalid read of size 4
> ==15175==    at 0x4B24FDB: pthread_join (in /lib/libpthread-2.3.6.so)
> ==15175==    by 0x405C6F: Thread::~Thread() (in 
> /home/naspab/Taller/TP4/server)==15175==    by 0x403AE3: 
> Server::~Server() (in /home/naspab/Taller/TP4/server)
> ==15175==    by 0x40311E: main (in /home/naspab/Taller/TP4/server)
> ==15175==  Address 0x5BFB9F0 is not stack'd, malloc'd or (recently) 
> free'd   Aca se ve que haces join de algo invalido al llamar al 
> destructorde algun thread. Busca lo siguiente:
>       Joineo de un thread que ya termino
>       y mas probable...destruccion de un Thread ya destruido.
>   Si compilas con -g podriamos ver los numero de linea.
>   Solucionado eso probablemente no pierdas mas memoria.
> 
>      Saludos
> 
> On 5/13/07, [EMAIL PROTECTED] 
> <[EMAIL PROTECTED]> wrote:
> > Buenas. Les comento el error que tengo. Yo tengo un thread 
> Server, que recibe Clientes (Threads), procesa sus solicitudes y 
> manda respuesta a cada uno. Cada vez que entra un cliente, creo un 
> nuevo thread llamado ClientHandler, haciendo un new. Luego, lo 
> agrego a un Vector de ClientHandlers, que es static, y pertenece a 
> la clase Server.
> > En el caso de que introduzca 3 o menos clienthandlers, cuando el 
> server termina (no recibe mas clientes), el programa cierra 
> correctamente. En el caso de recibir 4 o mas clientes, el programa 
> pincha justo en el join del thread server.
> >
> >
> >
> > [EMAIL PROTECTED]:~/Taller/TP4$ valgrind --leak-check=full ./server 
> 10091 4
> > ==15175== Memcheck, a memory error detector.
> > ==15175== Copyright (C) 2002-2005, and GNU GPL'd, by Julian 
> Seward et al.
> > ==15175== Using LibVEX rev 1471, a library for dynamic binary 
> translation.> ==15175== Copyright (C) 2004-2005, and GNU GPL'd, by 
> OpenWorks LLP.
> > ==15175== Using valgrind-3.1.0-Debian, a dynamic binary 
> instrumentation framework.
> > ==15175== Copyright (C) 2000-2005, and GNU GPL'd, by Julian 
> Seward et al.
> > ==15175== For more details, rerun with: -v
> > ==15175==
> > Ingreso un cliente!
> > Ingreso un cliente!
> > Ingreso un cliente!
> > Ingreso un cliente!
> > Ultima linea del main del Server!
> > Cliente 1
> > Hice el stop!
> > Hice el join!
> > Borre un Thread!
> > Hice el Borrado!
> >
> > Cliente 2
> > Hice el stop!
> > Hice el join!
> > Borre un Thread!
> > Hice el Borrado!
> >
> > Cliente 3
> > Hice el stop!
> > Hice el join!
> > Borre un Thread!
> > Hice el Borrado!
> >
> > Cliente 4
> > Hice el stop!
> > Hice el join!
> > Borre un Thread!
> > Hice el Borrado!
> >
> > Vaciado OK de ClientHandlers!
> > Fin del destructor del Server!
> > ==15175== Invalid read of size 4
> > ==15175==    at 0x4B24FDB: pthread_join (in /lib/libpthread-
> 2.3.6.so)> ==15175==    by 0x405C6F: Thread::~Thread() (in 
> /home/naspab/Taller/TP4/server)> ==15175==    by 0x403AE3: 
> Server::~Server() (in /home/naspab/Taller/TP4/server)
> > ==15175==    by 0x40311E: main (in /home/naspab/Taller/TP4/server)
> > ==15175==  Address 0x5BFB9F0 is not stack'd, malloc'd or 
> (recently) free'd
> > ==15175==
> > ==15175== Process terminating with default action of signal 11 
> (SIGSEGV)> ==15175==  Access not within mapped region at address 
> 0x5BFB9F0> ==15175==    at 0x4B24FDB: pthread_join (in 
> /lib/libpthread-2.3.6.so)
> > ==15175==    by 0x405C6F: Thread::~Thread() (in 
> /home/naspab/Taller/TP4/server)> ==15175==    by 0x403AE3: 
> Server::~Server() (in /home/naspab/Taller/TP4/server)
> > ==15175==    by 0x40311E: main (in /home/naspab/Taller/TP4/server)
> > ==15175==
> > ==15175== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 8 
> from 1)
> > ==15175== malloc/free: in use at exit: 2,187 bytes in 25 blocks.
> > ==15175== malloc/free: 164 allocs, 139 frees, 5,287 bytes allocated.
> > ==15175== For counts of detected errors, rerun with: -v
> > ==15175== searching for pointers to 25 not-freed blocks.
> > ==15175== checked 33,846,712 bytes.
> > ==15175==
> > ==15175==
> > ==15175== 507 bytes in 18 blocks are possibly lost in loss record 
> 3 of 5
> > ==15175==    at 0x4A19DE3: operator new(unsigned long) 
> (vg_replace_malloc.c:168)> ==15175==    by 0x4CCBC7C: 
> std::string::_Rep::_S_create(unsigned long, unsigned long, 
> std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.7)
> > ==15175==    by 0x4CCC07B: (within /usr/lib/libstdc++.so.6.0.7)
> > ==15175==    by 0x4CCC211: std::string::string(char const*, 
> std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.7)
> > ==15175==    by 0x403ED2: 
> __static_initialization_and_destruction_0(int, int) (in 
> /home/naspab/Taller/TP4/server)> ==15175==    by 0x406C01: (within 
> /home/naspab/Taller/TP4/server)> ==15175==    by 0x4018F2: (within 
> /home/naspab/Taller/TP4/server)> ==15175==
> > ==15175==
> > ==15175== 544 bytes in 4 blocks are possibly lost in loss record 
> 4 of 5
> > ==15175==    at 0x4A1AD7D: calloc (vg_replace_malloc.c:279)
> > ==15175==    by 0x400DCA8: _dl_allocate_tls (in /lib/ld-2.3.6.so)
> > ==15175==    by 0x4B246B8: pthread_create@@GLIBC_2.2.5 (in 
> /lib/libpthread-2.3.6.so)
> > ==15175==    by 0x405DC6: Thread::run() (in 
> /home/naspab/Taller/TP4/server)> ==15175==    by 0x403D3A: 
> Server::main() (in /home/naspab/Taller/TP4/server)
> > ==15175==    by 0x405CA9: Thread::static_run(void*) (in 
> /home/naspab/Taller/TP4/server)> ==15175==    by 0x4B240F9: 
> start_thread (in /lib/libpthread-2.3.6.so)
> > ==15175==    by 0x5189CE1: clone (in /lib/libc-2.3.6.so)
> > ==15175==
> > ==15175== LEAK SUMMARY:
> > ==15175==    definitely lost: 0 bytes in 0 blocks.
> > ==15175==      possibly lost: 1,051 bytes in 22 blocks.
> > ==15175==    still reachable: 1,136 bytes in 3 blocks.
> > ==15175==         suppressed: 0 bytes in 0 blocks.
> > ==15175== Reachable blocks (those to which a pointer was found) 
> are not shown.
> > ==15175== To see them, rerun with: --show-reachable=yes
> > Fallo de segmentación
> >
> >
> > ------------------------------------
> >
> > El tema es que no entiendo la diferencia que hay en que entren 3, 
> 5 o 100 clientes. Si la ejecucion con 3 clientes en paralelo 
> funciona perfectamente, entonces, si entran 5, deberia ir bien igual.
> > Lo raro ademas es que si entran 10 clientes, los trata bien el 
> server, aceptando sus solicitudes, y mandando respuestas adecuadas 
> a todos los clientes. Luego los borra del vector de clientHandlers, 
> y ni bien termina la ultima linea del destructor del Server, cuando 
> llama al destructor de thread ( lo unico que hace es un join() ), 
> entonces ahi pincha.
> >
> > Si alguien tiene alguna idea de donde esta el error, por favor, 
> aviseme!> Muchas gracias!
> > Pablo Statile
> >
> >
> > _______________________________________________
> > Lista de correo Programacion.
> > [email protected]
> > http://listas.fi.uba.ar/mailman/listinfo/programacion
> >
> 
> _______________________________________________
> Lista de correo Programacion.
> [email protected]
> http://listas.fi.uba.ar/mailman/listinfo/programacion
> 

_______________________________________________
Lista de correo Programacion.
[email protected]
http://listas.fi.uba.ar/mailman/listinfo/programacion

Responder a