From ea0e4fc2567edfc0d20141025837e2bd9c64c0cb Mon Sep 17 00:00:00 2001
From: opneErler BUildteam <buildteam@openeuler.org>
Date: Fri, 5 Jun 2020 15:46:37 +0800
Subject: [PATCH] fix memleaks in asn1 arrat2tree

---
 lib/parser_aux.c |  2 +-
 lib/structure.c  | 20 +++++++++----
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/parser_aux.c b/lib/parser_aux.c
index d5dbbf8..071f1be 100644
--- a/lib/parser_aux.c
+++ b/lib/parser_aux.c
@@ -767,7 +767,7 @@ _asn1_expand_object_id (list_type **list, asn1_node node)
 			return ASN1_ELEMENT_NOT_FOUND;
 
 		      _asn1_set_down (p, p2->right);
-		      if (p2->down)
+                     while (p2->down)
 			_asn1_delete_structure (*list, &p2->down, 0);
 		      _asn1_delete_node_from_list(*list, p2);
 		      _asn1_remove_node (p2, 0);
diff --git a/lib/structure.c b/lib/structure.c
index 8189c56..6dfba58 100644
--- a/lib/structure.c
+++ b/lib/structure.c
@@ -207,13 +207,13 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
 
       if (move == DOWN)
 	{
-	  if (p_last && p_last->down)
+	  while (p_last && p_last->down)
 	      _asn1_delete_structure (e_list, &p_last->down, 0);
 	  _asn1_set_down (p_last, p);
 	}
       else if (move == RIGHT)
         {
-	  if (p_last && p_last->right)
+	  while (p_last && p_last->right)
 	      _asn1_delete_structure (e_list, &p_last->right, 0);
 	  _asn1_set_right (p_last, p);
         }
@@ -317,7 +317,7 @@ int
 _asn1_delete_structure (list_type *e_list, asn1_node * structure, unsigned int flags)
 {
   asn1_node p, p2, p3;
-
+  int flag_t = 1;
   if (*structure == NULL)
     return ASN1_ELEMENT_NOT_FOUND;
 
@@ -347,7 +347,11 @@ _asn1_delete_structure (list_type *e_list, asn1_node * structure, unsigned int f
 		{
 		  p3 = _asn1_find_up (p);
 		  if (p3)
+                 {
 		    _asn1_set_down (p3, p2);
+                   p2 = NULL;
+                   flag_t = 0;
+                 }
 		  else
 		    {
 		      if (p->right)
@@ -355,15 +359,19 @@ _asn1_delete_structure (list_type *e_list, asn1_node * structure, unsigned int f
 		    }
 		}
 	      else
-		_asn1_set_right (p3, p2);
+               {
+                 _asn1_set_right (p3,p2);
+                 p2 = NULL;
+                 flag_t = 0;
+               }
 	      if (e_list)
 		_asn1_delete_node_from_list (e_list, p);
 	      _asn1_remove_node (p, flags);
-	      p = NULL;
+	      p = p2;
 	    }
 	}
     }
-
+if (flag_t)
   *structure = NULL;
   return ASN1_SUCCESS;
 }
-- 
1.8.3.1

