Merge "(1)	In ECM use-case, if doing fast plug-in/plug-out within 2s, the IPACM sometimes will crash due to rmnet0 didn't have TX-property, add checking there (2)	Event-dispatcher has some bugs when instance closes, somehow IPACM will access the freed memory location try to find next link-list cell"
diff --git a/ipacm/src/IPACM_EvtDispatcher.cpp b/ipacm/src/IPACM_EvtDispatcher.cpp
index 60f0e8d..c76f760 100644
--- a/ipacm/src/IPACM_EvtDispatcher.cpp
+++ b/ipacm/src/IPACM_EvtDispatcher.cpp
@@ -109,7 +109,7 @@
 void IPACM_EvtDispatcher::ProcessEvt(ipacm_cmd_q_data *data)
 {
 
-	cmd_evts *tmp = head;
+	cmd_evts *tmp = head, tmp1;
 
 	if(head == NULL)
 	{
@@ -118,12 +118,13 @@
 
 	while(tmp != NULL)
 	{
-		if(data->event == tmp->event)
+	        memcpy(&tmp1, tmp, sizeof(tmp1));
+		if(data->event == tmp1.event)
 		{
-			tmp->obj->event_callback(data->event, data->evt_data);
+			tmp1.obj->event_callback(data->event, data->evt_data);
 			IPACMDBG(" Find matched registered events\n");
 		}
-		tmp = tmp->next;
+	        tmp = tmp1.next;
 	}
 
 	IPACMDBG(" Finished process events\n");
diff --git a/ipacm/src/IPACM_Filtering.cpp b/ipacm/src/IPACM_Filtering.cpp
index 4241549..083a409 100644
--- a/ipacm/src/IPACM_Filtering.cpp
+++ b/ipacm/src/IPACM_Filtering.cpp
@@ -164,13 +164,14 @@
 	 uint32_t *flt_rule_hdls,
 	 ipa_ip_type ip,
 	 uint8_t num_rules
-	 )
+)
 {
 	struct ipa_ioc_del_flt_rule *flt_rule;
 	bool res = true;
 	int len = 0, cnt = 0;
+        const uint8_t UNIT_RULES = 1;
 
-	len = (sizeof(struct ipa_ioc_del_flt_rule)) + (num_rules * sizeof(struct ipa_flt_rule_del));
+	len = (sizeof(struct ipa_ioc_del_flt_rule)) + (UNIT_RULES * sizeof(struct ipa_flt_rule_del));
 	flt_rule = (struct ipa_ioc_del_flt_rule *)malloc(len);
 	if (flt_rule == NULL)
 	{
@@ -178,41 +179,43 @@
 		return false;
 	}
 
-	memset(flt_rule, 0, len);
-	flt_rule->commit = 1;
-	flt_rule->num_hdls = num_rules;
-	flt_rule->ip = ip;
-
-	for (cnt = 0; cnt < flt_rule->num_hdls; cnt++)
+	for (cnt = 0; cnt < num_rules; cnt++)
 	{
+	    memset(flt_rule, 0, len);
+	    flt_rule->commit = 1;
+	    flt_rule->num_hdls = UNIT_RULES;
+	    flt_rule->ip = ip;
 
-		if (flt_rule_hdls[cnt] == 0)
-		{
-			IPACMERR("invalid filter handle passed, ignoring it: %d\n", cnt)
-			res = false;
-			goto fail;
-		}
+	    if (flt_rule_hdls[cnt] == 0)
+	    {
+		   IPACMERR("invalid filter handle passed, ignoring it: %d\n", cnt)
+	    }
+            else
+	    {
 
-		flt_rule->hdl[cnt].status = -1;
-		flt_rule->hdl[cnt].hdl = flt_rule_hdls[cnt];
-		IPACMDBG("Deleting filter hdl:(0x%x) with ip type: %d\n", flt_rule_hdls[cnt], ip);
-	}
+		   flt_rule->hdl[0].status = -1;
+		   flt_rule->hdl[0].hdl = flt_rule_hdls[cnt];
+		   IPACMDBG("Deleting filter hdl:(0x%x) with ip type: %d\n", flt_rule_hdls[cnt], ip);
 
-	if (DeleteFilteringRule(flt_rule) == false)
-	{
-		PERROR("Filter rule deletion failed!\n");
-		res = false;
-		goto fail;
-	}
+	           if (DeleteFilteringRule(flt_rule) == false)
+	           {
+		        PERROR("Filter rule deletion failed!\n");
+		        res = false;
+		        goto fail;
+	           }
+		   else
+	           {
 
-	for (cnt = 0; cnt < flt_rule->num_hdls; cnt++)
-	{
-		if (flt_rule->hdl[cnt].status != 0)
-		{
-			IPACMERR("Filter rule hdl 0x%x deletion failed with error:%d\n",
-							 flt_rule->hdl[cnt].hdl, flt_rule->hdl[cnt].status);
-			res = false;
-		}
+		        if (flt_rule->hdl[0].status != 0)
+		        {
+			     IPACMERR("Filter rule hdl 0x%x deletion failed with error:%d\n",
+		        					 flt_rule->hdl[0].hdl, flt_rule->hdl[0].status);
+			     res = false;
+			     goto fail;
+		        }
+		   
+		   }	   
+	    }
 	}
 
 fail:
diff --git a/ipacm/src/IPACM_Iface.cpp b/ipacm/src/IPACM_Iface.cpp
index 745d921..736c84a 100644
--- a/ipacm/src/IPACM_Iface.cpp
+++ b/ipacm/src/IPACM_Iface.cpp
@@ -576,7 +576,10 @@
 	}
 	else
 	{
-	  IPACM_Iface::ipacmcfg->AddRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[rx_prop->rx[0].src_pipe]);		
+	  if(rx_prop != NULL)
+	  {
+	      IPACM_Iface::ipacmcfg->AddRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[rx_prop->rx[0].src_pipe]);		
+	  }
 	}
 #else
   	IPACM_Iface::ipacmcfg->AddRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[rx_prop->rx[0].src_pipe]);
diff --git a/ipacm/src/IPACM_Lan.cpp b/ipacm/src/IPACM_Lan.cpp
index 7bb6cad..95f042a 100644
--- a/ipacm/src/IPACM_Lan.cpp
+++ b/ipacm/src/IPACM_Lan.cpp
@@ -1299,6 +1299,7 @@
 		}
 	}
 
+        IPACMDBG("Finished delete default iface ipv4 filtering rules \n ");
 
 	if (ip_type != IPA_IP_v4 && rx_prop != NULL)
 	{
@@ -1312,6 +1313,8 @@
 		}
 	}
 
+        IPACMDBG("Finished delete default iface ipv6 filtering rules \n ");
+	
 	/* delete wan filter rule */
 	if (IPACM_Wan::isWanUP() && rx_prop != NULL)
 	{
diff --git a/ipacm/src/IPACM_Wan.cpp b/ipacm/src/IPACM_Wan.cpp
index 7ee68d5..f8e180d 100644
--- a/ipacm/src/IPACM_Wan.cpp
+++ b/ipacm/src/IPACM_Wan.cpp
@@ -398,6 +398,12 @@
 	/* copy header from tx-property, see if partial or not */
 	/* assume all tx-property uses the same header name for v4 or v6*/
 
+	if(tx_prop == NULL)
+	{
+	  IPACMDBG("No tx properties, ignore default route setting\n");
+	  return IPACM_SUCCESS;
+	}
+	
         for (cnt=0; cnt<tx_prop->num_tx_props; cnt++)
 	{
 		   if(tx_prop->tx[cnt].ip==iptype)
@@ -623,6 +629,12 @@
 
 	IPACMDBG("got handle_route_del_evt with ip-family:%d \n", iptype);
 
+	if(tx_prop == NULL)
+	{
+	  IPACMDBG("No tx properties, ignore delete default route setting\n");
+	  return IPACM_SUCCESS;
+	}		
+	
 	if (((iptype == IPA_IP_v4) && (active_v4 == true)) ||
 			((iptype == IPA_IP_v6) && (active_v6 == true)))
 	{