[SR-Users] memory leak fix on xcap_ auth.c

laura testi lau.testi at gmail.com
Mon Jan 30 13:01:07 CET 2012


Hi Daniel,
I'm sending you some memory leak fix we have found and fixed on
modules/utils/xcap_ auth.c.

The fixed memory leak is in pres_watcher_allowed (), and it is about
the "xmlFreeDoc" that it's never called for the "xcap_tree" variable.

We downloaded the source file from master branch and then we fixed it.
You can find here the diff from original and new code and in attach
both the original and the new files.


diff -u a/modules/utils/xcap_auth.c b/modules/utils/xcap_auth.c
--- a/modules/utils/xcap_auth.c
+++ b/modules/utils/xcap_auth.c
@@ -280,13 +280,15 @@
     }

     node= get_rule_node(subs, xcap_tree);
-    if (node== NULL)
+    if (node== NULL){
+  xmlFreeDoc(xcap_tree);
        return 0;
-
+               }
     /* process actions */
     actions_node = xmlNodeGetChildByName(node, "actions");
     if (actions_node == NULL) {
        LM_DBG("actions_node NULL\n");
+       xmlFreeDoc(xcap_tree);
        return 0;
     }
     LM_DBG("actions_node->name= %s\n", actions_node->name);
@@ -294,6 +296,7 @@
     sub_handling_node = xmlNodeGetChildByName(actions_node, "sub-handling");
     if (sub_handling_node== NULL) {
        LM_DBG("sub_handling_node NULL\n");
+       xmlFreeDoc(xcap_tree);
        return 0;
     }
     sub_handling = (char*)xmlNodeGetContent(sub_handling_node);
@@ -302,6 +305,7 @@

     if (sub_handling == NULL) {
        LM_ERR("Couldn't get sub-handling content\n");
+       xmlFreeDoc(xcap_tree);
        return -1;
     }
     if (strncmp((char*)sub_handling, "block", 5) == 0) {
@@ -325,10 +329,12 @@
            else {
                LM_ERR("unknown subscription handling action\n");
                xmlFree(sub_handling);
+               xmlFreeDoc(xcap_tree);
                return -1;
            }

     xmlFree(sub_handling);
+    xmlFreeDoc(xcap_tree);

     return 0;

Kind Regards,
laura
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xcap_auth.c.new
Type: application/octet-stream
Size: 14528 bytes
Desc: not available
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20120130/5240259a/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xcap_auth.c.orig
Type: application/octet-stream
Size: 13839 bytes
Desc: not available
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20120130/5240259a/attachment-0003.obj>


More information about the sr-users mailing list