<div style="font-size:10pt; font-family:Gulim;"><p>Hello freeswitch-users,&nbsp;</p><p>&nbsp;</p><p>there is some doubt about memory leak in freeswitch implemetation.</p><p>&nbsp;</p><p>when a channel is created, some mutex&nbsp;are created as below.</p><p style="font-size: 10pt;">&nbsp;</p><p style="font-size: 10pt;">SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel, switch_call_direction_t direction, switch_memory_pool_t *pool)<br>{<br>&nbsp;&nbsp;&nbsp; switch_assert(pool != NULL);</p><p style="font-size: 10pt;">&nbsp;&nbsp;&nbsp; if (((*channel) = switch_core_alloc(pool, sizeof(switch_channel_t))) == 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return SWITCH_STATUS_MEMERR;<br>&nbsp;&nbsp;&nbsp; }</p><p style="font-size: 10pt;">&nbsp;&nbsp;&nbsp; switch_event_create_plain(&amp;(*channel)-&gt;variables, SWITCH_EVENT_CHANNEL_DATA);</p><p style="font-size: 10pt;">&nbsp;&nbsp;&nbsp; switch_core_hash_init(&amp;(*channel)-&gt;private_hash, pool);<br>&nbsp;&nbsp;&nbsp; switch_queue_create(&amp;(*channel)-&gt;dtmf_queue, SWITCH_DTMF_LOG_LEN, pool);<br>&nbsp;&nbsp;&nbsp; switch_queue_create(&amp;(*channel)-&gt;dtmf_log_queue, SWITCH_DTMF_LOG_LEN, pool);</p><p style="font-size: 10pt;">&nbsp;&nbsp;&nbsp; switch_mutex_init(&amp;(*channel)-&gt;dtmf_mutex, SWITCH_MUTEX_NESTED, pool);<br>&nbsp;&nbsp;&nbsp; switch_mutex_init(&amp;(*channel)-&gt;flag_mutex, SWITCH_MUTEX_NESTED, pool);<br>&nbsp;&nbsp;&nbsp; switch_mutex_init(&amp;(*channel)-&gt;state_mutex, SWITCH_MUTEX_NESTED, pool);<br>&nbsp;&nbsp;&nbsp; switch_mutex_init(&amp;(*channel)-&gt;thread_mutex, SWITCH_MUTEX_NESTED, pool);<br>&nbsp;&nbsp;&nbsp; switch_mutex_init(&amp;(*channel)-&gt;profile_mutex, SWITCH_MUTEX_NESTED, pool);<br>&nbsp;&nbsp;&nbsp; ...</p><p style="font-size: 10pt;">}</p><p>&nbsp;</p><p style="font-size: 10pt;">And,&nbsp;&nbsp;It seems that some memory is newly allocated in switch_mutex_init() by comments in the following code.</p><p style="font-size: 10pt;">&nbsp;</p><p style="font-size: 10pt;">[&nbsp;switch_apr.h ]</p><p style="font-size: 10pt;">/**<br>&nbsp;* Create and initialize a mutex that can be used to synchronize threads.<br>&nbsp;* @param lock the memory address where the newly created mutex will be<br>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stored.<br>&nbsp;* @param flags Or'ed value of:<br>&nbsp;* &lt;PRE&gt;<br>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SWITCH_THREAD_MUTEX_DEFAULT&nbsp;&nbsp; platform-optimal lock behavior.<br>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SWITCH_THREAD_MUTEX_NESTED&nbsp;&nbsp;&nbsp; enable nested (recursive) locks.<br>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SWITCH_THREAD_MUTEX_UNNESTED&nbsp; disable nested locks (non-recursive).<br>&nbsp;* &lt;/PRE&gt;<br>&nbsp;* @param pool the pool from which to allocate the mutex.<br>&nbsp;* @warning Be cautious in using SWITCH_THREAD_MUTEX_DEFAULT.&nbsp; While this is the<br>&nbsp;* most optimial mutex based on a given platform's performance charateristics,<br>&nbsp;* it will behave as either a nested or an unnested lock.<br>&nbsp;*<br>*/<br>SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t ** lock, unsigned int flags, switch_memory_pool_t *pool);</p><p style="font-size: 10pt;"><br>/**<br>&nbsp;* Destroy the mutex and free the memory associated with the lock.<br>&nbsp;* @param lock the mutex to destroy.<br>&nbsp;*/<br>SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t *lock);&nbsp;</p><p style="font-size: 10pt;">but, I can't find&nbsp;any code that is related with destroying mutex.</p><p style="font-size: 10pt;">&nbsp;</p><p style="font-size: 10pt;">In my opinion, </p><p style="font-size: 10pt;">altough a memory size is very tiny for creating mutex, the leaking memory will be more&nbsp;bigger as times go on.</p><p style="font-size: 10pt;">&nbsp;</p><p style="font-size: 10pt;">It doesn't need to destory the mutex when a channel is destory?</p><p style="font-size: 10pt;">&nbsp;</p><p style="font-size: 10pt;">could someone explain about this?</p><p style="font-size: 10pt;">&nbsp;</p><p style="font-size: 10pt;">Thank you in advance.</p><p style="font-size: 10pt;">&nbsp;</p><p style="font-size: 10pt;">Regards,</p><p style="font-size: 10pt;">hkchoi</p></div>
<table style="display:none"><tr><td><img src="http://mail.naver.com/readReceipt/notify/?img=oeFqDHk516mYar%2B5MBiCpzElaA2Za6MXMxtZFxCoKo%2BCpxkSFqpoF6k0MoJoKxJg%2BH%2B0Mouq74lR74lcWNFlbX30WLloWrdQarpZp6kq%2Br0dMr2R%2BBF0bNFgWz0q%2BHK5pNi0pBFX1B3o1VlTb4b%3D.gif" border="0"></td></tr></table>