ichina / doubango

Automatically exported from code.google.com/p/doubango
0 stars 1 forks source link

Potential memory-leak in tinySAK (tsk_thread.c) #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There is a potential memory in the "tsk_thread_create" function.

The first parameter is a pointer on a memory zone that will store the newly 
started thread handle. On Unix platform (with pthread), the pointed zone is 
allocated on the heap, but the deallocation only occurs if the 
"tsk_thread_join" is called.

Is it possible to add a note that specifies that the pointed zone needs to be 
freed by the caller in order to avoid memory leaks, either by calling 
"tsk_thread_join" or by freeing it ?

Original issue reported on code.google.com by laurent.etiemble@gmail.com on 22 Jun 2010 at 1:07

GoogleCodeExporter commented 9 years ago
The same applies to Windows platform. If "tsk_thread_join" is not called, the 
thread HANDLE is never deallocated (See MSDN 
http://msdn.microsoft.com/en-us/library/ms682453.aspx):

The thread object remains in the system until the thread has terminated and all 
handles to it have been closed through a call to CloseHandle.

Original comment by laurent.etiemble@gmail.com on 22 Jun 2010 at 1:25

GoogleCodeExporter commented 9 years ago
By convention, void** parameters are used to return values. As the returned 
value is a pointer this means that the caller is responsible for the newly 
allocated memory. If you don't wish to use "tsk_thread_join()", then you could 
simply use CloseHandle() or free() in the thread's id.
To avoid zombie threads, it's highly recommended to call tsk_thread_join().

Original comment by boss...@yahoo.fr on 28 Jun 2010 at 1:19

GoogleCodeExporter commented 9 years ago

Original comment by boss...@yahoo.fr on 21 Aug 2010 at 10:17