Browse code

core: xvavp - new data type SR_XTYPE_SPTR

- store a shm pointer that has to be freed at destroy with shm_free()

Daniel-Constantin Mierla authored on 23/05/2019 07:30:51
Showing 2 changed files
... ...
@@ -57,6 +57,10 @@ void xavp_free(sr_xavp_t *xa)
57 57
 			xa->val.v.data->pfree(xa->val.v.data->p, xavp_shm_free);
58 58
 			shm_free(xa->val.v.data);
59 59
 		}
60
+	} else if(xa->val.type == SR_XTYPE_SPTR) {
61
+		if(xa->val.v.vptr) {
62
+			shm_free(xa->val.v.vptr);
63
+		}
60 64
 	} else if(xa->val.type == SR_XTYPE_XAVP) {
61 65
 		xavp_destroy_list(&xa->val.v.xavp);
62 66
 	}
... ...
@@ -70,6 +74,10 @@ void xavp_free_unsafe(sr_xavp_t *xa)
70 74
 			xa->val.v.data->pfree(xa->val.v.data->p, xavp_shm_free_unsafe);
71 75
 			shm_free_unsafe(xa->val.v.data);
72 76
 		}
77
+	} else if(xa->val.type == SR_XTYPE_SPTR) {
78
+		if(xa->val.v.vptr) {
79
+			shm_free_unsafe(xa->val.v.vptr);
80
+		}
73 81
 	} else if(xa->val.type == SR_XTYPE_XAVP) {
74 82
 		xavp_destroy_list_unsafe(&xa->val.v.xavp);
75 83
 	}
... ...
@@ -588,6 +596,9 @@ void xavp_print_list_content(sr_xavp_t **head, int level)
588 596
 			case SR_XTYPE_VPTR:
589 597
 				LM_INFO("     XAVP value: <vptr:%p>\n", avp->val.v.vptr);
590 598
 			break;
599
+			case SR_XTYPE_SPTR:
600
+				LM_INFO("     XAVP value: <sptr:%p>\n", avp->val.v.vptr);
601
+			break;
591 602
 			case SR_XTYPE_DATA:
592 603
 				LM_INFO("     XAVP value: <data:%p>\n", avp->val.v.data);
593 604
 			break;
... ...
@@ -697,7 +708,7 @@ sr_xavp_t *xavp_clone_level_nodata(sr_xavp_t *xold)
697 708
 	{
698 709
 		return NULL;
699 710
 	}
700
-	if(xold->val.type==SR_XTYPE_DATA)
711
+	if(xold->val.type==SR_XTYPE_DATA || xold->val.type==SR_XTYPE_SPTR)
701 712
 	{
702 713
 		LM_INFO("xavp value type is 'data' - ignoring in clone\n");
703 714
 		return NULL;
... ...
@@ -720,7 +731,8 @@ sr_xavp_t *xavp_clone_level_nodata(sr_xavp_t *xold)
720 731
 
721 732
 	while(oavp)
722 733
 	{
723
-		if(oavp->val.type!=SR_XTYPE_DATA && oavp->val.type!=SR_XTYPE_XAVP)
734
+		if(oavp->val.type!=SR_XTYPE_DATA && oavp->val.type!=SR_XTYPE_XAVP
735
+				&& oavp->val.type!=SR_XTYPE_SPTR)
724 736
 		{
725 737
 			navp =  xavp_new_value(&oavp->name, &oavp->val);
726 738
 			if(navp==NULL)
... ...
@@ -33,7 +33,8 @@ typedef enum {
33 33
 	SR_XTYPE_LONG,    /* long value */
34 34
 	SR_XTYPE_LLONG,   /* long long value */
35 35
 	SR_XTYPE_XAVP,    /* xavp value */
36
-	SR_XTYPE_VPTR,    /* void pointer value */
36
+	SR_XTYPE_VPTR,    /* void pointer value (no free on destroy) */
37
+	SR_XTYPE_SPTR,    /* void pointer value (shm free on destroy) */
37 38
 	SR_XTYPE_DATA     /* custom data value */
38 39
 } sr_xtype_t;
39 40