Skip to content

Commit d5d1760

Browse files
committed
[tm] fix mem leak (lumps) upon async and sync jumps
If you do a 2 level async() op, where the first is actually handled in async mode while the second is in sync mode, the memory of added lumps will leak. Fixes OpenSIPS#3914 Credits for the report goes to @vadimd333
1 parent 80d48a9 commit d5d1760

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

‎modules/tm/sip_msg.c‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ int update_cloned_msg_from_msg(struct sip_msg *c_msg, struct sip_msg *msg)
12221222
return -1;
12231223
}
12241224

1225+
12251226
/* length of the new data lump structures */
12261227
l1_len = l2_len = l3_len = 0;
12271228
LUMP_LIST_LEN(l1_len, msg->add_rm);
@@ -1322,18 +1323,22 @@ int update_cloned_msg_from_msg(struct sip_msg *c_msg, struct sip_msg *msg)
13221323
free_sip_body( body_bk );
13231324
}
13241325

1325-
if (!(msg->msg_flags & FL_TM_FAKE_REQ)) {
1326-
/* if not a fake request, we should free old values right now,
1327-
* otherwise we leak if it's a fake request, then we can't free
1328-
* old info now - we might still need it ( eg. to build a reply
1329-
* from the faked req ) - let the freeing happen when destryong
1330-
* the fake req */
1331-
shm_lock();
1332-
if (add_rm_aux) shm_free_bulk(add_rm_aux);
1333-
if (body_lumps_aux) shm_free_bulk(body_lumps_aux);
1334-
if (reply_lump_aux) shm_free_bulk(reply_lump_aux);
1335-
shm_unlock();
1326+
if (msg->msg_flags & FL_TM_FAKE_REQ) {
1327+
/* fake requests are built based on the T->uas request, sharing
1328+
* the lump pointers; so, if we updated the T->uas (aka c_msg),
1329+
* we need to update the fake msg (aka msg) before freeing the
1330+
* old lumps */
1331+
if (l1_len) msg->add_rm = c_msg->add_rm;
1332+
if (l2_len) msg->body_lumps = c_msg->body_lumps;
1333+
if (l3_len) msg->reply_lump = c_msg->reply_lump;
1334+
/* this will also prevent free_fake_req() to free again the
1335+
* old lumps (as being different than t->uas */
13361336
}
1337+
shm_lock();
1338+
if (add_rm_aux) shm_free_bulk(add_rm_aux);
1339+
if (body_lumps_aux) shm_free_bulk(body_lumps_aux);
1340+
if (reply_lump_aux) shm_free_bulk(reply_lump_aux);
1341+
shm_unlock();
13371342

13381343
c_msg->msg_flags |= FL_SHM_UPDATED;
13391344
return 0;

0 commit comments

Comments
 (0)