Skip to content

Commit

Permalink
presence_xml: do not allocate memory before getting presence node
Browse files Browse the repository at this point in the history
- useless operation in case of error
  • Loading branch information
miconda committed Jul 31, 2017
1 parent 3001402 commit 3016679
Showing 1 changed file with 17 additions and 31 deletions.
48 changes: 17 additions & 31 deletions src/modules/presence_xml/notify_body.c
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 3016679

Please sign in to comment.