Ozzyboshi created an issue (kamailio/kamailio#4741)
### Potential memory leak in pv_headers module (pvh_merge_uri / XAVP handling)
I am observing a progressive increase in shared memory usage on a heavily
loaded Kamailio proxy server. The growth appears to correlate strongly with
operations in the pv_headers module, in particular pvh_merge_uri().
Over time (between restarts), shm usage increases significantly and does not
appear to be fully released, eventually leading to memory exhaustion under
sustained load.
The functions contributing most to memory usage in mod.stats are:
- pvh_merge_uri()
- pvh_set_uri()
- pvh_xavi_new_value()
Memory statistics
Before restart (high memory usage state)
```
Module: pv_headers
{
pvh_set_xavi(385): 9680
pvh_set_parsed(695): 201264
pvh_xavi_new_value(113): 3546288
pvh_set_uri(860): 136061408
pvh_merge_uri(1017): 16331792
pvh_merge_uri(919): 286319760
Total: 442470192
}
```
After restart (baseline)
```
Module: pv_headers
{
pvh_set_uri(860): 9200
pvh_merge_uri(1017): 2016
pvh_merge_uri(919): 37968
pvh_set_parsed(695): 9840
pvh_xavi_new_value(113): 46976
pvh_set_xavi(385): 416
Total: 106416
}
```
### Analysis
>From my investigation, pvh_merge_uri() appears to be the primary source of the
>memory growth.
The issue seems related to allocation handling inside pvh_xavp.c, specifically
around these code sections:
https://github.com/kamailio/kamailio/blob/046fbf9371a346e0beb99c8686a8e73076664b52/src/modules/pv_headers/pvh_xavp.c#L921
https://github.com/kamailio/kamailio/blob/046fbf9371a346e0beb99c8686a8e73076664b52/src/modules/pv_headers/pvh_xavp.c#L862
In particular, there are code paths where memory is allocated before calling
pvh_merge_uri(), but if the function returns -1, the allocated memory may not
be properly released.
Additionally, inside pvh_merge_uri() itself, there is another allocation
affecting c_data->value.s, which may also be leaked depending on the return
path.
See
https://github.com/kamailio/kamailio/blob/046fbf9371a346e0beb99c8686a8e73076664b52/src/modules/pv_headers/pvh_xavp.c#L921
### Reproduction
The issue can be reproduced under heavy load using a malformed assignment that
forces execution of the affected code path:
```
request_route
{
...
$x_fu =
"sip:playcfannounce@217159599;[email protected];user=phone";
}
```
#### Steps
- Apply the above configuration snippet
- Restart Kamailio
- Generate sustained SIP traffic (thousands of calls per hour)
#### Result
After approximately ~10 hours under load, shared memory usage grows steadily
until reaching multi-GB levels (observed up to ~4GB), requiring a restart.
### Additional Information
```
lsb_release -a
Linux sp2 6.12.85+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.85-1
(2026-04-30) x86_64 GNU/Linux
root@sp2:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 13 (trixie)
Release: 13
Codename: trixie
```
### Operating System:
```
uname -a
Linux sp2 6.12.85+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.85-1
(2026-04-30) x86_64 GNU/Linux
```
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4741
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!