[sr-dev] git:master:30166790: presence_xml: do not allocate memory before getting presence node

Daniel-Constantin Mierla miconda at gmail.com
Mon Jul 31 15:54:52 CEST 2017


Module: kamailio
Branch: master
Commit: 30166790b1b8addef006c7a933ac2c009a3998e2
URL: https://github.com/kamailio/kamailio/commit/30166790b1b8addef006c7a933ac2c009a3998e2

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-31T15:54:27+02:00

presence_xml: do not allocate memory before getting presence node

- useless operation in case of error

---

Modified: src/modules/presence_xml/notify_body.c

---

Diff:  https://github.com/kamailio/kamailio/commit/30166790b1b8addef006c7a933ac2c009a3998e2.diff
Patch: https://github.com/kamailio/kamailio/commit/30166790b1b8addef006c7a933ac2c009a3998e2.patch

---

diff --git a/src/modules/presence_xml/notify_body.c b/src/modules/presence_xml/notify_body.c
index 82b4a4d96e..8872c1dccc 100644
--- a/src/modules/presence_xml/notify_body.c
+++ b/src/modules/presence_xml/notify_body.c
@@ -233,17 +233,6 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 	char* content = NULL;
 	char all_name[KSR_FNB_NAME_SIZE+8];
 
-	strcpy(all_name, "all-");
-
-	new_body = (str*)pkg_malloc(sizeof(str));
-	if(new_body == NULL)
-	{
-		LM_ERR("while allocating memory\n");
-		return NULL;
-	}	
-
-	memset(new_body, 0, sizeof(str));
-
 	doc = xmlParseMemory(notify_body->s, notify_body->len);
 	if(doc== NULL) 
 	{
@@ -257,6 +246,16 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 		goto error;
 	}
 
+	strcpy(all_name, "all-");
+
+	new_body = (str*)pkg_malloc(sizeof(str));
+	if(new_body == NULL)
+	{
+		LM_ERR("while allocating memory\n");
+		return NULL;
+	}
+	memset(new_body, 0, sizeof(str));
+
 	transf_node = xmlNodeGetChildByName(rule_node, "transformations");
 	if(transf_node == NULL)
 	{
@@ -502,34 +501,21 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 	LM_DBG("body = \n%.*s\n", new_body->len,
 			new_body->s);
 
-    xmlFreeDoc(doc);
+	xmlFreeDoc(doc);
 
 	xmlFree(class_cont);
 	xmlFree(occurence_ID);
 	xmlFree(deviceID);
 	xmlFree(service_uri);
-    xmlCleanupParser();
-    xmlMemoryDump();
+	xmlCleanupParser();
+	xmlMemoryDump();
+
+	return new_body;
 
-    return new_body;
 error:
-    if(doc)
+    if(doc) {
 		xmlFreeDoc(doc);
-	if(new_body)
-	{
-		if(new_body->s)
-			xmlFree(new_body->s);
-		pkg_free(new_body);
-	}
-	if(class_cont)
-		xmlFree(class_cont);
-	if(occurence_ID)
-		xmlFree(occurence_ID);
-	if(deviceID)
-		xmlFree(deviceID);
-	if(service_uri)
-		xmlFree(service_uri);
-
+	}
 	return NULL;
 }	
 




More information about the sr-dev mailing list