Fixes #4503.
### Problem
Transactions leak when `drop;` executes in a `branch_route` and modules
like `pua_dialoginfo` are loaded. The leaked transactions persist
indefinitely in shared memory — no final reply is sent, no timer fires,
and `wait_handler()` never frees the cell.
### Cause
`set_kr()` accumulates flags with `|=`, but the first cleanup check in
`t_unref()` uses exact equality:
```c
if(unlikely(kr == REQ_ERR_DELAYED)) { // fails when other flags are set
```
When `pua_dialoginfo` processes an INVITE, it calls `dialog_publish_multi()`
inline during `DLGCB_CREATED`, which goes through `pua_send_publish()` →
`tmb.t_request()` → `t_uac_prepare()` → `set_kr(REQ_FWDED)`. If the
INVITE's `branch_route` then calls `drop;`, `t_relay_to()` ORs in
`REQ_ERR_DELAYED`, making `_tm_kr = REQ_FWDED | REQ_ERR_DELAYED` (17).
In `t_unref()`:
- Check 1: `17 == 16` → false
- Check 2: `17 == 0` → false
- Check 3: `(17 & 16)` true, but `(17 & ~(4|2|16|1))` = 0 → false
All three checks fail. The transaction is orphaned.
This affects any module that calls `t_request()` or `t_uac_prepare()` inline
during INVITE processing — `pua_dialoginfo` is one common example.
### Fix
Change the check from exact equality to a bitwise test:
```c
- if(unlikely(kr == REQ_ERR_DELAYED)) {
+ if(unlikely(kr & REQ_ERR_DELAYED)) {
```
The delayed-reply handler now fires whenever `REQ_ERR_DELAYED` is present,
regardless of other flags accumulated by `set_kr()`.
This is safe because:
- `REQ_ERR_DELAYED` is only set in `t_relay_to()` when `t_forward_nonack()`
fails and the delayed-reply path is chosen — it is never set spuriously.
- `kill_transaction()` already handles the case where a final reply was
previously sent (`FL_FINAL_REPLY` check → `t_release_transaction()`).
The existing check-3 fallback (lines 2077-2084) becomes unreachable after
this change but is harmless to leave in place.
### Workaround
On 6.1+ where `delayed_reply` is a runtime modparam, setting
`modparam("tm", "delayed_reply", 0)` avoids the vulnerable code path.
On ≤ 6.0.x, `TM_DELAYED_REPLY` is a compile-time `#define` (always on)
and there is no workaround — only this patch fixes the leak.
### Test results
Ten-scenario matrix across 6.0.3, 6.1.0, and 6.2.0-dev0 master. 1000
INVITEs per run, `fr_timer=5000`, `branch_route` with unconditional
`drop;`. Contamination triggered naturally by loading `dialog` + `pua` +
`pua_dialoginfo` — no source modification beyond this patch.
| # | Version | Patch | `delayed_reply` | current | 5xx | SHM delta | Verdict |
|---|---------|-------|:---------------:|--------:|----:|----------:|---------|
| 1 | 6.0.3 | no | x | 431 | 0 | +7,150,272 | **LEAK** |
| 2 | 6.0.3 | yes | x | 0 | 353 | 0 | OK |
| 3 | 6.1.0 | no | 1 | 431 | 0 | +7,287,200 | **LEAK** |
| 4 | 6.1.0 | no | 0 | 0 | 375 | 0 | OK |
| 5 | 6.1.0 | yes | 1 | 0 | 407 | 0 | OK |
| 6 | 6.1.0 | yes | 0 | 0 | 336 | 0 | OK |
| 7 | 6.2.0-dev0 | no | 1 | 446 | 0 | +7,770,288 | **LEAK** |
| 8 | 6.2.0-dev0 | no | 0 | 0 | 461 | 0 | OK |
| 9 | 6.2.0-dev0 | yes | 1 | 0 | 448 | 0 | OK |
| 10 | 6.2.0-dev0 | yes | 0 | 0 | 448 | 0 | OK |
`delayed_reply` = x: not available as a modparam (compile-time, always on).
`current`: transactions remaining in hash table after test.
`5xx`: 500 replies sent by the delayed-reply handler (nonzero = cleanup ran).
---
*Note: AI tooling was used to assist with the code analysis, reproduction,
and test automation for this issue. All diagnosis, testing, and review was
supervised by @NormB — the AI did not operate autonomously. The root cause
identification, fix selection, and validation were guided and verified at
each step.*
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/4644
-- Commit Summary --
* tm: use bitwise check for REQ_ERR_DELAYED in t_unref()
-- File Changes --
M src/modules/tm/t_lookup.c (2)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/4644.patchhttps://github.com/kamailio/kamailio/pull/4644.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/4644
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/pull/4644(a)github.com>
<!-- 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)
- [x] 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
- [x] Tested changes locally
- [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description
<!-- Describe your changes in detail -->
This PR add two validation tests related to VIA.
1. Check if VIA is present through the `required_headers` function. the docs suggest to check for it but code does not (not in this function anyway) (considered a bug?)
Another note though is that sanity module may be not really acting on this at all due to some sanity check found in (https://github.com/kamailio/kamailio/blob/41c30c244ca0ca8b3c201e0c02602b255…) and that kamailio cfg will drop the msg much earlier
2. Check if branch paramater is present in the Via header which is mandatory according to RFC. (new feature)
Also increase a dbg to err log and check for host len more stricly. 0-len host is not valid.
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/4643
-- Commit Summary --
* sanity: Add Via header to required_headers check
* sanity: Add branch sanity check for Via header
* sanity: Increase log to error
* sanity: Check host len more strictly
-- File Changes --
M src/modules/sanity/sanity.c (16)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/4643.patchhttps://github.com/kamailio/kamailio/pull/4643.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/4643
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/pull/4643(a)github.com>
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/9dc160d1d2bdf0542d3d9d8ae090bb135…
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/9dc160d1d2bdf0542d3d9d8ae090bb135…
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/9dc160d1d2bdf0542d3d9d8ae090bb135…
My concern is: is this cell always freed?
The matching cleanup function is free_cell(), used only here:
https://github.com/kamailio/kamailio/blob/9dc160d1d2bdf0542d3d9d8ae090bb135…
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/4503(a)github.com>
miconda created an issue (kamailio/kamailio#4621)
By using `cmake` to install and build, the `kamdbctl` cannot create database tables:
``` shell
kamdbctl: 292: cannot open ./mysql/standard-create.sql: No such file
```
Given that cmake is used to build the deb packages, I expect that it affects installations via debs as well.
I am holding releasing 6.1.1 for a bit, hoping to get this one fixed -- maybe others can help quickly.
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4621
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/issues/4621(a)github.com>
THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.
A user has added themself to the list of users assigned to this task.
FS#100 - Assignment operators don't work
User who did this - Alex Hermann (axlh)
http://sip-router.org/tracker/index.php?do=details&task_id=100
You are receiving this message because you have requested it from the Flyspray bugtracking system. If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.