<p>Vadim Yanitskiy <strong>uploaded patch set #2</strong> to this change.</p><p><a href="https://gerrit.osmocom.org/13450">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">libmsc/sms_queue.c: fix memleak in smsq_take_next_sms()<br><br>A memleak has been noticed after executing some of TTCN-3 test<br>cases. For example, the following ones:<br><br>  - MSC_Tests.TC_lu_and_mo_sms,<br>  - MSC_Tests.TC_lu_and_mt_sms.<br><br>The key point is that a test case basically disconnects too quickly,<br>leaving some MT SMS messages (e.g. delivery reports) undelivered,<br>so they are getting stored in the SMSC's database.<br><br>As soon as the SMSC's queue is triggered, sms_submit_pending() would<br>retrieve pending messages from the database by calling function<br>smsq_take_next_sms() in loop and attempt to deliver them.<br><br>This function in it's turn checks whether the subscriber is attached<br>or not. If not, the allocated 'gsm_sms' structure would not be<br>free()ed! Therefore, every time smsq_take_next_sms() is called,<br>one 'gsm_sms' structure for an unattached subscriber is leaked.<br><br>Furthermore, there is a unit test called 'sms_queue_test', that<br>actually does cover smsq_take_next_sms() and was designed to<br>catch some potential memory leaks, but...<br><br>In order to avoid emulating the low-level SQLite API, the unit<br>test by design overwrites some functions of libmsc, including<br>db_sms_get_next_unsent_rr_msisdn(), that is being called by<br>smsq_take_next_sms().<br><br>The problem is that the original function in libmsc does<br>allocate a 'gsm_sms' structure on heap (using talloc), while<br>the overwriting function did this statically, returning a<br>pointer to stack. This critical difference made it impossible<br>to spot the memleak in smsq_take_next_sms() during the<br>unit test execution.<br><br>Let's refactor 'sms_queue_test' to use dynamic memory allocation,<br>and finally fix the evil memleak in smsq_take_next_sms().<br><br>Change-Id: Iad5e4d84d8d410ea43d5907e9ddf6e5fdb55bc7a<br>Closes: OS#3860<br>---<br>M src/libmsc/sms_queue.c<br>M tests/sms_queue/sms_queue_test.c<br>2 files changed, 21 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/50/13450/2</pre><p>To view, visit <a href="https://gerrit.osmocom.org/13450">change 13450</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/13450"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-msc </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newpatchset </div>
<div style="display:none"> Gerrit-Change-Id: Iad5e4d84d8d410ea43d5907e9ddf6e5fdb55bc7a </div>
<div style="display:none"> Gerrit-Change-Number: 13450 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Vadim Yanitskiy <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr@sysmocom.de> </div>