Browse code

presence_xml: do not allocate memory before getting presence node

- useless operation in case of error

Daniel-Constantin Mierla authored on 31/07/2017 13:42:19
Showing 1 changed files
... ...
@@ -233,17 +233,6 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
233 233
 	char* content = NULL;
234 234
 	char all_name[KSR_FNB_NAME_SIZE+8];
235 235
 
236
-	strcpy(all_name, "all-");
237
-
238
-	new_body = (str*)pkg_malloc(sizeof(str));
239
-	if(new_body == NULL)
240
-	{
241
-		LM_ERR("while allocating memory\n");
242
-		return NULL;
243
-	}	
244
-
245
-	memset(new_body, 0, sizeof(str));
246
-
247 236
 	doc = xmlParseMemory(notify_body->s, notify_body->len);
248 237
 	if(doc== NULL) 
249 238
 	{
... ...
@@ -257,6 +246,16 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
257 257
 		goto error;
258 258
 	}
259 259
 
260
+	strcpy(all_name, "all-");
261
+
262
+	new_body = (str*)pkg_malloc(sizeof(str));
263
+	if(new_body == NULL)
264
+	{
265
+		LM_ERR("while allocating memory\n");
266
+		return NULL;
267
+	}
268
+	memset(new_body, 0, sizeof(str));
269
+
260 270
 	transf_node = xmlNodeGetChildByName(rule_node, "transformations");
261 271
 	if(transf_node == NULL)
262 272
 	{
... ...
@@ -502,34 +501,21 @@ done:
502 502
 	LM_DBG("body = \n%.*s\n", new_body->len,
503 503
 			new_body->s);
504 504
 
505
-    xmlFreeDoc(doc);
505
+	xmlFreeDoc(doc);
506 506
 
507 507
 	xmlFree(class_cont);
508 508
 	xmlFree(occurence_ID);
509 509
 	xmlFree(deviceID);
510 510
 	xmlFree(service_uri);
511
-    xmlCleanupParser();
512
-    xmlMemoryDump();
511
+	xmlCleanupParser();
512
+	xmlMemoryDump();
513
+
514
+	return new_body;
513 515
 
514
-    return new_body;
515 516
 error:
516
-    if(doc)
517
+    if(doc) {
517 518
 		xmlFreeDoc(doc);
518
-	if(new_body)
519
-	{
520
-		if(new_body->s)
521
-			xmlFree(new_body->s);
522
-		pkg_free(new_body);
523
-	}
524
-	if(class_cont)
525
-		xmlFree(class_cont);
526
-	if(occurence_ID)
527
-		xmlFree(occurence_ID);
528
-	if(deviceID)
529
-		xmlFree(deviceID);
530
-	if(service_uri)
531
-		xmlFree(service_uri);
532
-
519
+	}
533 520
 	return NULL;
534 521
 }	
535 522