Hello every body,<br><br>I am facing some problems in some custom changes in rtp.c file in which have used some threading functions.<br>I create a thread in ast_rtp_new_with_bindaddr function as below:<br><br> pthread_attr_t attr;<br>
rtp->thread_var=NULL;<br> pthread_attr_init(&attr);<br> ast_pthread_create_background(&rtp->thread_var,&attr, somecustom_thread,(void *)rtp);<br> pthread_attr_destroy(&attr);<br>
<br>Thread of "somecustom_thread" is being created, which continue in while loop (i.e. while(1))<br>I destroy this thread in ast_rtp_stop function with below line:<br><div style="margin-left: 40px;">pthread_cancel(rtp->thread_var);<br>
</div><b><br></b>My function works very fine in normal one-two calls. But when I put the modified asterisk in regression/stress testing (test with many calls of 20-30 second duration for long run), I finds the memory leaks as below under Valgrind:<br>
==19707== 98,320 bytes in 683 blocks are possibly lost in loss record 39 of 41<br>==19707== at 0x4004864: calloc (vg_replace_malloc.c:279)<br>==19707== by 0xB09109: _dl_allocate_tls (in /lib/<a href="http://ld-2.7.so">ld-2.7.so</a>)<br>
==19707== by 0xCA9BFE: pthread_create@@GLIBC_2.1 (in /lib/<a href="http://libpthread-2.7.so">libpthread-2.7.so</a>)<br>==19707== by 0x812276E: ast_pthread_create_stack (utils.c:910)<br>==19707== by 0x80EE60A: ast_rtp_new_with_bindaddr (rtp.c:2124)<br>
==19707== by 0x4AD8D0E: sip_alloc (chan_sip.c:4677)<br>==19707== by 0x4ADA318: find_call (chan_sip.c:4848)<br>==19707== by 0x4B152DA: sipsock_read (chan_sip.c:16485)<br>==19707== by 0x80C11B9: ast_io_wait (io.c:279)<br>
==19707== by 0x4B164D6: do_monitor (chan_sip.c:16772)<br>==19707== by 0x8122526: dummy_start (utils.c:856)<br>==19707== by 0xCA950A: start_thread (in /lib/<a href="http://libpthread-2.7.so">libpthread-2.7.so</a>)<br>
<br><b><br></b><br>This seems to be a problem with pthread library, but it only occurs which I do regression testing.<br>My question is that what is the mistake in creating and destroying the thread.<br>If the there is a mistake in my code of creating the thread, please let me know.<br>
If any body know better option to run the thread just after RTP media starts and stop the thread when RTP media stop, please point me into that direction.<br><br>Thanks in advance.<br><b><br></b>