Browse code

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

Jason Penton authored on 10/03/2014 12:35:47
Showing 2 changed files
... ...
@@ -829,8 +829,13 @@ int set_path_vector(struct sip_msg* msg, str* path)
829 829
 
830 830
 void reset_path_vector(struct sip_msg* const msg)
831 831
 {
832
-	if(msg->path_vec.s != 0) {
832
+	/* only free path vector from pkg IFF it is still in pkg... - ie. if msg is shm we don't free... */
833
+	if (msg->path_vec.s && likely(msg->path_vec.s >= msg->buf && (msg->path_vec.s < (msg->buf + msg->len)))) {
833 834
 		pkg_free(msg->path_vec.s);
835
+	} else {
836
+		if (msg->path_vec.s)
837
+			/* don't reset path_vec if it is shm */
838
+			return;
834 839
 	}
835 840
 	msg->path_vec.s = 0;
836 841
 	msg->path_vec.len = 0;
... ...
@@ -395,6 +395,8 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
395 395
 	/*the dst uri (if any)*/
396 396
 	if (org_msg->dst_uri.s && org_msg->dst_uri.len)
397 397
 		len+= ROUND4(org_msg->dst_uri.len);
398
+	if (org_msg->path_vec.s && org_msg->path_vec.len)
399
+			len+= ROUND4(org_msg->path_vec.len);
398 400
 	/*all the headers*/
399 401
 	for( hdr=org_msg->headers ; hdr ; hdr=hdr->next )
400 402
 	{
... ...
@@ -522,6 +524,7 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
522 522
 	/* zero *uri.s, in case len is 0 but org_msg->*uris!=0 (just to be safe)*/
523 523
 	new_msg->new_uri.s = 0;
524 524
 	new_msg->dst_uri.s = 0;
525
+	new_msg->path_vec.s = 0;
525 526
 	/* new_uri */
526 527
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
527 528
 	{
... ...
@@ -536,9 +539,13 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
536 536
 		memcpy( p , org_msg->dst_uri.s , org_msg->dst_uri.len);
537 537
 		p += ROUND4(org_msg->dst_uri.len);
538 538
 	}
539
-	/* path_vec is not cloned (it's reset instead) */
540
-	new_msg->path_vec.s=0;
541
-	new_msg->path_vec.len=0;
539
+	/* path vector */
540
+	if (org_msg->path_vec.s && org_msg->path_vec.len) {
541
+		new_msg->path_vec.s = p;
542
+		memcpy(p, org_msg->path_vec.s, org_msg->path_vec.len);
543
+		p += ROUND4(org_msg->path_vec.len);
544
+	}
545
+
542 546
 	/* instance is not cloned (it's reset instead) */
543 547
 	new_msg->instance.s=0;
544 548
 	new_msg->instance.len=0;