I've detected that the allocated shared memory is always growing due to
``` proxy[2527]: NOTICE: fm_status: count=376594 size= 103410648 bytes from usrloc: ucontact.c: new_ucontact(98) proxy[2527]: NOTICE: fm_status: count=1882939 size= 110079752 bytes from usrloc: ../../ut.h: shm_str_dup(723) ``` we do have usrloc in db_mode 3 ( DB_ONLY ).
This is kamailio 4.4.4 version
Investigation underway.
I would say the origin of the problem is calls to get_urecord() without release_urecord() ``` /*! * \brief Release urecord previously obtained through get_urecord * \warning Failing to calls this function after get_urecord will * result in a memory leak when the DB_ONLY mode is used. When * the records is later deleted, e.g. with delete_urecord, then * its not necessary, as this function already releases the record. * \param _r released record */ void release_urecord(urecord_t* _r) { if (db_mode==DB_ONLY) { free_urecord(_r); } else if (_r->contacts == 0) { mem_delete_urecord(_r->slot->d, _r); } } ```
added some debug
notice in this example that ``ucontact[0x7f7b315f1d08]`` is never freed REGISTER ``` Feb 16 17:04:43 sp1 proxy[9687]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:53152 (127.0.0.1:5060) ID=8e40daa391b6e4d82b296c77eb0c6986@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315f1d08] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: registrar [path.c:108]: build_path_vector(): received is sip:192.168.1.42:53152 Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: registrar [path.c:116]: build_path_vector(): path is <sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:53152;socket=sip:192.168.1.71:5060> Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a5cd82-25d7-1 Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: registrar [save.c:591]: test_max_contacts(): 1 valid contacts Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: registrar [save.c:613]: test_max_contacts(): 2 contacts after commit Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a5cd82-25d7-2 Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315f2100] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ul_callback.h:84]: run_ul_callbacks(): contact=0x7f7b315f2100, callback type 1/1, id 0 entered Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:245]: reginfo_usrloc_cb(): AOR: 43993005@192.168.1.71 (location) Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:246]: reginfo_usrloc_cb(): type= UL_CONTACT_INSERT Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315f24f8] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315f28f0] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:105]: build_reginfo_full(): Updated Contact sip:43993005@192.168.1.42:53152;transport=udp;registering_acc=192_168_1_ 71[uloc-58a5cd82-25d7-2] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:111]: build_reginfo_full(): Contact sip:43993005@192.168.1.42:30210;transport=udp;registering_acc=192_168_1_71[uloc- 58a5c7d4-497a-1] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:111]: build_reginfo_full(): Contact sip:43993005@192.168.1.42:53152;transport=udp;registering_acc=192_168_1_71[uloc- 58a5cd82-25d7-2] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:303]: reginfo_usrloc_cb(): XML-Body:#012<?xml version="1.0"?>#012<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" ver sion="0" state="full">#012 <registration aor="sip:43993005@192.168.1.71" id="0x7f7b41740200" state="active">#012 <contact id="0x7f7b315f24f8" state="active" event="registered" e xpires="206" callid="3643dd620caf238de37dca05e8bbfbcf@0.0.0.0" cseq="6" received="sip:192.168.1.42:30210" path="<sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:30210;socket=sip:19 2.168.1.71:5060>" user_agent="Jitsi2.9.5521Linux">#012 <uri>sip:43993005@192.168.1.42:30210;transport=udp;registering_acc=192_168_1_71</uri>#012 </contact>#012 <contac t id="0x7f7b315f28f0" state="active" event="created" expires="565" callid="8e40daa391b6e4d82b296c77eb0c6986@0.0.0.0" cseq="2" received="sip:192.168.1.42:53152" path="<sip:lb@127. 0.0.1;lr;received=sip:192.168.1.42:53152;socket=sip:192.168.1.71:5060>" user_agent="Jitsi2.9.5521Linux">#012 <uri>sip:43993005@192.168.1.42:53152;transport=udp;registering_a cc=192_168_1_71</uri>#012 </contact>#012 </registration>#012</reginfo>#012 Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:305]: reginfo_usrloc_cb(): Contact sip:43993005@192.168.1.42:53152;transport=udp;registering_acc=192_168_1_71, 0x7f7 b315f2100 Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f7b315f24f8] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f7b315f28f0] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: NOTICE: <script>: Contacts successfully saved, expires in 600s - R=sip:192.168.1.71 ID=8e40daa391b6e4d82b296c77eb0c6986@0.0.0.0 UA='Jitsi2.9.5521Lin ux' ``` UNREGISTER ``` Feb 16 17:13:15 sp1 proxy[9687]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:53152 (127.0.0.1:5060) ID=8e40daa391b6e4d82b296c77eb0c6986@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f7b41740200] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315faa90] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7f7b41740200] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: registrar [path.c:108]: build_path_vector(): received is sip:192.168.1.42:53152 Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: registrar [path.c:116]: build_path_vector(): path is <sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:53152;socket=sip:192.168.1.71:5060> Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a5cd82-25d7-3 Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: registrar [save.c:591]: test_max_contacts(): 1 valid contacts Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: registrar [save.c:613]: test_max_contacts(): 0 contacts after commit Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a5cd82-25d7-4 Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [ul_callback.h:84]: run_ul_callbacks(): contact=0x7f7b315faa90, callback type 4/4, id 3 entered Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:245]: reginfo_usrloc_cb(): AOR: 43993005@192.168.1.71 (location) Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:249]: reginfo_usrloc_cb(): type= UL_CONTACT_DELETE Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f7b41740200] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315fae28] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7f7b41740200] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:105]: build_reginfo_full(): Updated Contact sip:43993005@192.168.1.42:53152;transport=udp;registering_acc=192_168_1_71[uloc-58a5cd82-25d7-2] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:111]: build_reginfo_full(): Contact sip:43993005@192.168.1.42:53152;transport=udp;registering_acc=192_168_1_71[uloc-58a5cd82-25d7-2] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:303]: reginfo_usrloc_cb(): XML-Body:#012<?xml version="1.0"?>#012<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="0" state="full">#012 <registration aor="sip:43993005@192.168.1.71" id="0x7f7b41740200" state="terminated">#012 <contact id="0x7f7b315fae28" state="terminated" event="unregistered" expires="53" callid="8e40daa391b6e4d82b296c77eb0c6986@0.0.0.0" cseq="2" received="sip:192.168.1.42:53152" path="<sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:53152;socket=sip:192.168.1.71:5060>" user_agent="Jitsi2.9.5521Linux">#012 <uri>sip:43993005@192.168.1.42:53152;transport=udp;registering_acc=192_168_1_71</uri>#012 </contact>#012 </registration>#012</reginfo>#012 Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: pua_reginfo [usrloc_cb.c:305]: reginfo_usrloc_cb(): Contact sip:43993005@192.168.1.42:53152;transport=udp;registering_acc=192_168_1_71, 0x7f7b315faa90 Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f7b41740200] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f7b315fae28] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:1788]: uldb_delete_attrs_ruid(): trying to delete location attributes Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f7b315faa90] Feb 16 17:13:15 sp1 proxy[9687]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f7b41740200] Feb 16 17:13:15 sp1 proxy[9687]: NOTICE: <script>: Contacts successfully deleted - R=sip:192.168.1.71 ID=8e40daa391b6e4d82b296c77eb0c6986@0.0.0.0 UA='Jitsi2.9.5521Linux' ```
without pua_reginfo
REGISTER ``` Feb 17 09:40:56 sp1 proxy[25182]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:36771 (127.0.0.1:5060) ID=4e4be68b480e519ae701a8ebd2f426ee@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 17 09:40:56 sp1 proxy[25182]: NOTICE: <script>: Authentication failed, no credentials - R=sip:192.168.1.71 ID=4e4be68b480e519ae701a8ebd2f426ee@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 17 09:40:56 sp1 proxy[25182]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:36771 (127.0.0.1:5060) ID=4e4be68b480e519ae701a8ebd2f426ee@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: usrloc [udomain.c:641]: db_load_urecord(): aor 43993005@192.168.1.71 not found in table location Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f02f3e08200] Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: registrar [path.c:108]: build_path_vector(): received is sip:192.168.1.42:36771 Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: registrar [path.c:116]: build_path_vector(): path is <sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:36771;socket=sip:192.168.1.71:5060> Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6b704-625e-1 Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f02e3cfee60] Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: registrar [reply.c:366]: build_contact(): created Contact HF: Contact: sip:43993005@192.168.1.42:36771;transport=udp;registering_acc=192_168_1_71;expires=564;received="sip:192.168.1.42:36771"#015#012 Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f02f3e08200] Feb 17 09:40:56 sp1 proxy[25182]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f02e3cfee60] Feb 17 09:40:56 sp1 proxy[25182]: NOTICE: <script>: Contacts successfully saved, expires in 600s - R=sip:192.168.1.71 ID=4e4be68b480e519ae701a8ebd2f426ee@0.0.0.0 UA='Jitsi2.9.5521Linux' ``` no ucontact in shared memory
UNREGISTER ``` Feb 17 09:41:04 sp1 proxy[25182]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:36771 (127.0.0.1:5060) ID=4e4be68b480e519ae701a8ebd2f426ee@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f02f3e08200] Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f02e3cfedf8] Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7f02f3e08200] Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: registrar [path.c:108]: build_path_vector(): received is sip:192.168.1.42:36771 Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: registrar [path.c:116]: build_path_vector(): path is <sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:36771;socket=sip:192.168.1.71:5060> Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6b704-625e-2 Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: registrar [save.c:591]: test_max_contacts(): 1 valid contacts Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: registrar [save.c:613]: test_max_contacts(): 0 contacts after commit Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6b704-625e-3 Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: usrloc [ucontact.c:1788]: uldb_delete_attrs_ruid(): trying to delete location attributes Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f02e3cfedf8] Feb 17 09:41:04 sp1 proxy[25182]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f02f3e08200] Feb 17 09:41:04 sp1 proxy[25182]: NOTICE: <script>: Contacts successfully deleted - R=sip:192.168.1.71 ID=4e4be68b480e519ae701a8ebd2f426ee@0.0.0.0 UA='Jitsi2.9.5521Linux' ``` no ucontact in shared memory
Your comments are quite minimalistic and didn't have time to look deeper at this potential issue. Are you saying that the issue is triggered by pua_reginfo?
We use registrations with dbmode =3 with no problems and we don't use pua_reginfo
On Friday, February 17, 2017, Daniel-Constantin Mierla < notifications@github.com> wrote:
Your comments are quite minimalistic and didn't have time to look deeper at this potential issue. Are you saying that the issue is triggered by pua_reginfo?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kamailio/kamailio/issues/997#issuecomment-280591788, or mute the thread https://github.com/notifications/unsubscribe-auth/AAvDrHyMJULLsRjhHH7fgaYsfA7gnoeRks5rdV--gaJpZM4MC6n1 .
Yes, the problem is happening for me because of pua_reginfo and I did https://github.com/linuxmaniac/kamailio/commit/2152b8c3ad4b1d61c4a456f7cb082... in order to solve it. But even with that I still get ucontac at shared mem left.
I'm suspecting that the underlying problem is the combination of get_static_urecord() + ul_callbacks + get_static_urecord(). The urecord is the same and it gets freed twice so only the first ucontact is free and the other is leaked.
see https://github.com/kamailio/kamailio/issues/997#issuecomment-280377848
REGISTER ``` Feb 16 17:04:43 sp1 proxy[9687]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:53152 (127.0.0.1:5060) ID=8e40daa391b6e4d82b296c77eb0c6986@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315f1d08] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7f7b41740200] ``` ``urecord static[0x7f7b41740200]`` is called before ul_callbacks and ``ucontact[0x7f7b315f1d08]`` is created.
now pua_reginfo ``` Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315f24f8] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7f7b315f28f0] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7f7b41740200] ```
``get_urecord()`` is called and the static ``urecord[0x7f7b41740200]`` is used and the new ``ucontact[0x7f7b315f28f0]`` and ``ucontact[0x7f7b315f24f8]`` are there.
This code has my fix so release_urecord() is called by pua_reginfo ``` Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f7b41740200] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f7b315f24f8] Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7f7b315f28f0] ``` and ``ucontact[0x7f7b315f28f0]`` and ``ucontact[0x7f7b315f24f8]`` are freed, perfect, but after the ul_callback now release_urecord() of the static ``urecord[0x7f7b41740200]`` has no efect
``` Feb 16 17:04:43 sp1 proxy[9687]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7f7b41740200] ```
so the initial ``ucontact[0x7f7b315f1d08]`` is not freed and the leak is done.
I would suggest as possible solutions: - remove the ``get_static_urecord()`` and the use proper reserved memory for ``urecord`` and free that at ``release_urecord()`` - keep a copy of ``urecord`` before calling ul_callbacks so we can safely free the ``ucontact`` afterwards
Being the second the less intrusive I think. Any ideas?
Is the PR #998 implementing the second option you suggested above?
No. #998 is implementing the missing ``release_urecord()`` after ``get_urecord()`` call.
So there is still going to be an issue after merging #998? Or that's the complete fix for the problem?
There will be still an issue after merging #998 but the situation will improved, there will be less leaks.
without the patch in a REGISTER/UPDATE REGISTER/UNREGISTER scenario I get left ``` Feb 17 11:20:52 sp1 proxy[12364]: NOTICE: fm_status: count= 30 size= 1416 bytes from usrloc: ../../ut.h: shm_str_dup(723) Feb 17 11:20:52 sp1 proxy[12364]: NOTICE: fm_status: count= 5 size= 1160 bytes from usrloc: ucontact.c: new_ucontact(98) ```
with the patch
``` Feb 17 11:32:36 sp1 proxy[24941]: NOTICE: fm_status: count= 18 size= 840 bytes from usrloc: ../../ut.h: shm_str_dup(723) Feb 17 11:32:36 sp1 proxy[24941]: NOTICE: fm_status: count= 3 size= 992 bytes from usrloc: ucontact.c: new_ucontact(98)
```
3 ``ucontacts`` from every REGISTER message received and not freed after ul_callbacks
Should I start working on the solution second solution? Is that the best approach?
With #998 and #1000 applied and some debug
REGISTER ``` Feb 17 14:03:55 sp1 proxy[22494]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:23583 (127.0.0.1:5060) ID=2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:641]: db_load_urecord(): aor 43993005@192.168.1.71 not found in table location Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7fe7be1a1200] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: registrar [path.c:108]: build_path_vector(): received is sip:192.168.1.42:23583 Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: registrar [path.c:116]: build_path_vector(): path is <sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:23583;socket=sip:192.168.1.71:5060> Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6f487-57de-1 Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7fe7ae088248] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [ul_callback.h:84]: run_ul_callbacks(): contact=0x7fe7ae088248, callback type 1/1, id 0 entered Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:245]: reginfo_usrloc_cb(): AOR: 43993005@192.168.1.71 (location) Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:246]: reginfo_usrloc_cb(): type= UL_CONTACT_INSERT Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7fe7be1a1200] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7fe7ae088640] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7fe7be1a1200] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:105]: build_reginfo_full(): Updated Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71[uloc-58a6f487-57de-1] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:111]: build_reginfo_full(): Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71[uloc-58a6f487-57de-1] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:303]: reginfo_usrloc_cb(): XML-Body:#012<?xml version="1.0"?>#012<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="0" state="full">#012 <registration aor="sip:43993005@192.168.1.71" id="0x7fe7be1a1200" state="active">#012 <contact id="0x7fe7ae088640" state="active" event="created" expires="434" callid="2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0" cseq="2" received="sip:192.168.1.42:23583" path="<sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:23583;socket=sip:192.168.1.71:5060>" user_agent="Jitsi2.9.5521Linux">#012 <uri>sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71</uri>#012 </contact>#012 </registration>#012</reginfo>#012 Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:305]: reginfo_usrloc_cb(): Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71, 0x7fe7ae088248 Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7fe7be1a1200] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7fe7ae088640] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: registrar [reply.c:366]: build_contact(): created Contact HF: Contact: sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71;expires=434;received="sip:192.168.1.42:23583"#015#012 Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7fe7be1a1200] Feb 17 14:03:55 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7fe7ae088248] Feb 17 14:03:55 sp1 proxy[22494]: NOTICE: <script>: Contacts successfully saved, expires in 600s - R=sip:192.168.1.71 ID=2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0 UA='Jitsi2.9.5521Linux' ```
Both ``ucontact[0x7fe7ae088248]`` and ``ucontact[0x7fe7ae088640]`` are freed now
UPDATE REGISTER
``` Feb 17 14:04:10 sp1 proxy[22494]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:23583 (127.0.0.1:5060) ID=2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7fe7be1a1200] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7fe7ae086930] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7fe7be1a1200] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: registrar [path.c:108]: build_path_vector(): received is sip:192.168.1.42:23583 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: registrar [path.c:116]: build_path_vector(): path is <sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:23583;socket=sip:192.168.1.71:5060> Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6f487-57de-2 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: registrar [save.c:591]: test_max_contacts(): 1 valid contacts Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: registrar [save.c:613]: test_max_contacts(): 1 contacts after commit Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6f487-57de-3 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:1005]: db_update_ucontact_ruid(): ruid:uloc-58a6f487-57de-1 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:1134]: db_update_ucontact_ruid(): contact:sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:1693]: update_ucontact(): exists callback for type= UL_CONTACT_UPDATE Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ul_callback.h:84]: run_ul_callbacks(): contact=0x7fe7ae086930, callback type 2/2, id 2 entered Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:245]: reginfo_usrloc_cb(): AOR: 43993005@192.168.1.71 (location) Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:247]: reginfo_usrloc_cb(): type= UL_CONTACT_UPDATE Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7fe7be1a1200] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7fe7ae086d28] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7fe7be1a1200] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:105]: build_reginfo_full(): Updated Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71[uloc-58a6f487-57de-1] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:111]: build_reginfo_full(): Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71[uloc-58a6f487-57de-1] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:303]: reginfo_usrloc_cb(): XML-Body:#012<?xml version="1.0"?>#012<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="0" state="full">#012 <registration aor="sip:43993005@192.168.1.71" id="0x7fe7be1a1200" state="active">#012 <contact id="0x7fe7ae086d28" state="active" event="refreshed" expires="598" callid="2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0" cseq="3" received="sip:192.168.1.42:23583" path="<sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:23583;socket=sip:192.168.1.71:5060>" user_agent="Jitsi2.9.5521Linux">#012 <uri>sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71</uri>#012 </contact>#012 </registration>#012</reginfo>#012 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:305]: reginfo_usrloc_cb(): Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71, 0x7fe7ae086930 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7fe7be1a1200] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7fe7ae086d28] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: registrar [reply.c:366]: build_contact(): created Contact HF: Contact: sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71;expires=598;received="sip:192.168.1.42:23583"#015#012 Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7fe7be1a1200] Feb 17 14:04:10 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7fe7ae086930] Feb 17 14:04:10 sp1 proxy[22494]: NOTICE: <script>: Contacts successfully updated, expires in 600s - R=sip:192.168.1.71 ID=2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0 UA='Jitsi2.9.5521Linux' ```
both ``ucontact[0x7fe7ae086930]`` and ``ucontact[0x7fe7ae086d28]`` are freed, no leak detected.
UNREGISTER
``` Feb 17 14:05:51 sp1 proxy[22494]: NOTICE: <script>: New request on proxy - M=REGISTER R=sip:192.168.1.71 F=sip:43993005@192.168.1.71 T=sip:43993005@192.168.1.71 IP=192.168.1.42:2358 3 (127.0.0.1:5060) ID=2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0 UA='Jitsi2.9.5521Linux' Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7fe7be1a1200] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7fe7ae089760] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7fe7be1a1200] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: registrar [path.c:108]: build_path_vector(): received is sip:192.168.1.42:23583 Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: registrar [path.c:116]: build_path_vector(): path is <sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:23583;socket=sip:192.168.1.71:5060> Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6f487-57de-01 Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: registrar [save.c:591]: test_max_contacts(): 1 valid contacts Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: registrar [save.c:613]: test_max_contacts(): 0 contacts after commit Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: registrar [save.c:410]: pack_ci(): generated ruid is: uloc-58a6f487-57de-11 Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [ul_callback.h:84]: run_ul_callbacks(): contact=0x7fe7ae089760, callback type 4/4, id 3 entered Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:245]: reginfo_usrloc_cb(): AOR: 43993005@192.168.1.71 (location) Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:249]: reginfo_usrloc_cb(): type= UL_CONTACT_DELETE Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:174]: get_static_urecord(): urecord static[0x7fe7be1a1200] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:142]: new_ucontact(): new ucontact[0x7fe7ae089b58] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [udomain.c:1155]: get_urecord(): DB_ONLY urecord[0x7fe7be1a1200] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:105]: build_reginfo_full(): Updated Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1 _71[uloc-58a6f487-57de-1] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:111]: build_reginfo_full(): Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71[uloc -58a6f487-57de-1] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:303]: reginfo_usrloc_cb(): XML-Body:#012<?xml version="1.0"?>#012<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" ve rsion="0" state="full">#012 <registration aor="sip:43993005@192.168.1.71" id="0x7fe7be1a1200" state="terminated">#012 <contact id="0x7fe7ae089b58" state="terminated" event="unre gistered" expires="409" callid="2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0" cseq="9" received="sip:192.168.1.42:23583" path="<sip:lb@127.0.0.1;lr;received=sip:192.168.1.42:23583;so cket=sip:192.168.1.71:5060>" user_agent="Jitsi2.9.5521Linux">#012 <uri>sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71</uri>#012 </contact>#012 </registration>#012</reginfo>#012 Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: pua_reginfo [usrloc_cb.c:305]: reginfo_usrloc_cb(): Contact sip:43993005@192.168.1.42:23583;transport=udp;registering_acc=192_168_1_71, 0x7f e7ae089760 Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7fe7be1a1200] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7fe7ae089b58] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:1797]: uldb_delete_attrs_ruid(): trying to delete location attributes Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [ucontact.c:179]: free_ucontact(): free ucontact[0x7fe7ae089760] Feb 17 14:05:51 sp1 proxy[22494]: DEBUG: usrloc [urecord.c:553]: release_urecord(): free urecord[0x7fe7be1a1200] Feb 17 14:05:51 sp1 proxy[22494]: NOTICE: <script>: Contacts successfully deleted - R=sip:192.168.1.71 ID=2b992fcc401d153fccd64bcdd8fed57b@0.0.0.0 UA='Jitsi2.9.5521Linux' ```
Both ``ucontact[0x7fe7ae089760]`` and ``ucontact[0x7fe7ae089b58]`` are freed, no leak detected.
@miconda should I merge both PRs? Can I backport them to 5.0 before the release?
They will be merged (or fixed in another way) and backported before release. But I didn't have the time to look properly at the commit in PR. I saw you do copy of the structure content, but then the backup variable is declared also static, meaning it is safe for one more layer ... but probably it's better to comment on PR itself, which is in my todo, just didn't get to it.
I guess this can be closed, after the PRs were merged.
Closed #997.