Browse code

lost: fixed possible resource leak inside lost_get_response_issues()

(cherry picked from commit a1bbe035f1a1acc11f86d27fdc0adef1b1a3d010)

Wolfgang Kampichler authored on 28/04/2021 15:22:58
Showing 1 changed files
... ...
@@ -573,39 +573,53 @@ p_lost_issue_t lost_get_response_issues(xmlNodePtr node)
573 573
 	cur = node->children;
574 574
 	while(cur) {
575 575
 		if(cur->type == XML_ELEMENT_NODE) {
576
-			/* get a new response type element */
576
+			/* get a new response type object */
577 577
 			issue = lost_new_response_type();
578 578
 			if(issue == NULL) {
579 579
 				/* didn't get it ... return */
580 580
 				break;
581 581
 			}
582
-			/* parse properties */
583
-			issue->source = lost_get_property(cur->parent, MAPP_PROP_SRC, &len);
582
+			/* get issue type */
584 583
 			tmp.s = (char *)cur->name;
585 584
 			tmp.len = strlen((char *)cur->name);
585
+			/* copy issue type to object */
586
+			len = 0;
586 587
 			if(tmp.len > 0 && tmp.s != NULL) {
587 588
 				issue->type = lost_copy_string(tmp, &len);
588 589
 			}
589
-			if(len > 0) {
590
+			if(len == 0) {
591
+				/* issue type not found, clean up and return */
592
+				lost_delete_response_type(&issue); /* clean up */
593
+				break;
594
+			}
595
+			/* parse source property */
596
+			len = 0;
597
+			issue->source = lost_get_property(cur->parent, MAPP_PROP_SRC, &len);
598
+			if(len == 0) {
599
+				/* source property not found, clean up and return */
600
+				lost_delete_response_type(&issue); /* clean up */
601
+				break;
602
+			}			
590 603
 
591
-				LM_DBG("###\t[%s]\n", issue->type);
604
+			LM_DBG("###\t[%s]\n", issue->type);
592 605
 
593
-				if(issue->info != NULL) {
594
-					issue->info->text = lost_get_property(cur, PROP_MSG, &len);
595
-					issue->info->lang = lost_get_property(cur, PROP_LANG, &len);
596
-				}
597
-				/* get a new list element */
598
-				new = lost_new_response_issues();
599
-				if(new == NULL) {
600
-					/* didn't get it, delete response type element ... return */
601
-					lost_delete_response_type(&issue); /* clean up */
602
-					break;
603
-				}
604
-				/* append to list */
605
-				new->issue = issue;
606
-				new->next = list;
607
-				list = new;
606
+			/* type and source property found ... parse text and copy */ 
607
+			if(issue->info != NULL) {
608
+				issue->info->text = lost_get_property(cur, PROP_MSG, &len);
609
+				issue->info->lang = lost_get_property(cur, PROP_LANG, &len);
608 610
 			}
611
+			/* get a new list element */
612
+			new = lost_new_response_issues();
613
+			if(new == NULL) {
614
+				/* didn't get it, clean up and return */
615
+				lost_delete_response_type(&issue); /* clean up */
616
+				break;
617
+			}
618
+			/* parsing done, append object to list */
619
+			new->issue = issue;
620
+			new->next = list;
621
+			list = new;
622
+
609 623
 			/* get next element */
610 624
 			cur = cur->next;
611 625
 		}