Ozzyboshi created an issue (kamailio/kamailio#4503)

Hello,

on my Kamailio installation I am experiencing a significant memory leak in SHM.
Here are the details of my system:

```
version: kamailio 6.0.3 (x86_64/linux) 
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, 
USE_MCAST,
       NO_SIG_DEBUG, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, MEM_JOIN_FREE, 
       Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX,
       FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, 
       USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS: 1024
MAX_RECV_BUFFER_SIZE: 262144
MAX_SEND_BUFFER_SIZE: 262144
MAX_URI_SIZE: 1024
BUF_SIZE: 65535
DEFAULT PKG_SIZE: 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select
compiled with gcc 14.2.0
```

The memory leak appears only when the presence feature is enabled.

When presence is active, Kamailio starts running dialog_publish(), whose code 
is here:

https://github.com/kamailio/kamailio/blob/9dc160d1d2bdf0542d3d9d8ae090bb1352520a1c/src/modules/pua_dialoginfo/dialog_publish.c#L291

This function does not send the PUBLISH directly: it calls pua_send_publish(), 
which is a function pointer referring to the send_publish() implementation in 
the pua module.
Then send_publish() eventually calls set_uac_req() and tmb.t_request():

https://github.com/kamailio/kamailio/blob/9dc160d1d2bdf0542d3d9d8ae090bb1352520a1c/src/modules/pua/send_publish.c#L617

Digging further, tmb.t_request() maps to request() in the TM module, which 
calls t_uac_with_ids() and then t_uac_prepare().

Now comes the suspicious part:

If I comment out the call to t_uac_prepare(), the memory leak disappears.
This doesn’t necessarily mean the bug is inside t_uac_prepare(), but it’s a 
strong hint.

t_uac_prepare() allocates a new struct cell and returns it:

https://github.com/kamailio/kamailio/blob/9dc160d1d2bdf0542d3d9d8ae090bb1352520a1c/src/modules/tm/uac.c#L511

My concern is: is this cell always freed?

The matching cleanup function is free_cell(), used only here:

https://github.com/kamailio/kamailio/blob/9dc160d1d2bdf0542d3d9d8ae090bb1352520a1c/src/modules/tm/uac.c#L683

>From what I can tell, free_cell() is called only if all these conditions are 
>true:

- dst_cell == 0
- is_ack == 1
- dst_req == 0
- 
In my situation no ACK is involved (Kamailio is a proxy that sends PUBLISH and 
immediately gets a 200 OK).
Therefore, is_ack is always false meaning the free_cell() cleanup logic is 
skipped entirely.

I tried forcing free_cell() unconditionally, but it leads to crashes, so 
clearly other parts of the code still rely on this structure.

Does the current free_cell() logic look correct to you?
Is it expected that struct cell allocated by t_uac_prepare() remains unfreed in 
cases where PUBLISH → 200 OK occurs without ACK?

Any guidance on how to proceed or where else to look would be greatly 
appreciated.

Thanks

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4503
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/[email protected]>
_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to