[sr-dev] git:master: core: parser: path_vector is now copied into shared memory when cloning

Jason Penton jason.penton at gmail.com
Mon Mar 10 13:38:40 CET 2014


Module: sip-router
Branch: master
Commit: 4ab0f53ff247f411dde7b88d5b7d82fc7e17baa9
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4ab0f53ff247f411dde7b88d5b7d82fc7e17baa9

Author: Jason Penton <jason.penton at gmail.com>
Committer: Jason Penton <jason.penton at gmail.com>
Date:   Mon Mar 10 14:35:47 2014 +0200

core: parser: path_vector is now copied into shared memory when cloning
	- fixes in place to cater for freeing memory correctly

---

 parser/msg_parser.c |    7 ++++++-
 sip_msg_clone.c     |   13 ++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/parser/msg_parser.c b/parser/msg_parser.c
index 1631401..f430b3f 100644
--- a/parser/msg_parser.c
+++ b/parser/msg_parser.c
@@ -829,8 +829,13 @@ int set_path_vector(struct sip_msg* msg, str* path)
 
 void reset_path_vector(struct sip_msg* const msg)
 {
-	if(msg->path_vec.s != 0) {
+	/* only free path vector from pkg IFF it is still in pkg... - ie. if msg is shm we don't free... */
+	if (msg->path_vec.s && likely(msg->path_vec.s >= msg->buf && (msg->path_vec.s < (msg->buf + msg->len)))) {
 		pkg_free(msg->path_vec.s);
+	} else {
+		if (msg->path_vec.s)
+			/* don't reset path_vec if it is shm */
+			return;
 	}
 	msg->path_vec.s = 0;
 	msg->path_vec.len = 0;
diff --git a/sip_msg_clone.c b/sip_msg_clone.c
index 1bb55ee..40a5e90 100644
--- a/sip_msg_clone.c
+++ b/sip_msg_clone.c
@@ -395,6 +395,8 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
 	/*the dst uri (if any)*/
 	if (org_msg->dst_uri.s && org_msg->dst_uri.len)
 		len+= ROUND4(org_msg->dst_uri.len);
+	if (org_msg->path_vec.s && org_msg->path_vec.len)
+			len+= ROUND4(org_msg->path_vec.len);
 	/*all the headers*/
 	for( hdr=org_msg->headers ; hdr ; hdr=hdr->next )
 	{
@@ -522,6 +524,7 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
 	/* zero *uri.s, in case len is 0 but org_msg->*uris!=0 (just to be safe)*/
 	new_msg->new_uri.s = 0;
 	new_msg->dst_uri.s = 0;
+	new_msg->path_vec.s = 0;
 	/* new_uri */
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
 	{
@@ -536,9 +539,13 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
 		memcpy( p , org_msg->dst_uri.s , org_msg->dst_uri.len);
 		p += ROUND4(org_msg->dst_uri.len);
 	}
-	/* path_vec is not cloned (it's reset instead) */
-	new_msg->path_vec.s=0;
-	new_msg->path_vec.len=0;
+	/* path vector */
+	if (org_msg->path_vec.s && org_msg->path_vec.len) {
+		new_msg->path_vec.s = p;
+		memcpy(p, org_msg->path_vec.s, org_msg->path_vec.len);
+		p += ROUND4(org_msg->path_vec.len);
+	}
+
 	/* instance is not cloned (it's reset instead) */
 	new_msg->instance.s=0;
 	new_msg->instance.len=0;




More information about the sr-dev mailing list