<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [X] Commit message has the format required by CONTRIBUTING guide - [X] Commits are split per component (core, individual modules, libs, utils, ...) - [X] Each component has a single commit (if not, squash them into one commit) - [X] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [X] Small bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [ ] PR should be backported to stable branches - [ ] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail -->
Setup: uac_req_send() with evroute=2 and tm module enable_uac_fr=1
Noticed following shm errors while intensively testing uac_req_send(), happening quite soon after a fresh restart (e.g. 10 min): ``` kamailio[5384]: ERROR: <core> [core/mem/q_malloc.c:297]: qm_find_free(): qm_find_free(0x7fe8943bc000, 40632); Free fragment not found! kamailio[5384]: ERROR: <core> [core/mem/q_malloc.c:430]: qm_malloc(): qm_malloc(0x7fe8943bc000, 40632) called from uac: uac_send.c: uac_send_info_clone(105), module: uac; Free fragment not found! kamailio[5384]: ERROR: uac [uac_send.c:108]: uac_send_info_clone(): no more shm memory kamailio[5384]: ERROR: uac [uac_send.c:837]: uac_req_send(): cannot clone the uac structure ``` I tried monitoring system memory using `free` tool and noticed that the "used" memory didn't grow alot. However, I noticed the "buff/cached" memory had a steep growth when 200OK(s) started to come, for my setup.
Noticed that, for my setup, when 200OK come, event_route[uac:reply] is not called, so the tm callback set by UAC module is not called. => the "tp" callback parameter shm allocated by UAC module is not freed.
By analogy, when using uac_req_send() with evroute=1 and timeout happens (e.g. no reply comes), event_route[uac:reply] won't be called and same leak should happen => *i didn;t tested that*, was just an analogy.
I updated the code to call the callback on TMCB_DESTROY, and make sure tp parameter is freed, *one time*.
Let me know what you think of this... in my setup/tests I got no kamailio shm logs anymore. Also "buff/cached" memory didn't have that steep growth anymore.
Thank you, Stefan
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/3065
-- Commit Summary --
* uac: fix shm leak
-- File Changes --
M src/modules/uac/uac_send.c (14)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/3065.patch https://github.com/kamailio/kamailio/pull/3065.diff
Thanks for the pull request. Just a small note regarding the debugging - standard system monitoring tools like free will in most cases not be that useful for detecting memory leaks, due to the Kamailio internal memory manager. But as you already got out of memory log messages in the logs, it strongly suggest a memory leak. You could use the kamailio memory debugging to get more detailled information, but in this case its probably not necessary.
@smititelu pushed 1 commit.
f8fbd8799fcde341bada9b41bfa6e2795ccaff6b uac: fix shm leak
Updated PR to NOT call event_route if code==0. This was happening for TMCB_DESTROY event.
Merged #3065 into master.