[Reconnoiter-devel] [reconnoiter commit] Reconnoiter branch, master, updated. e88e9e38ef3322a56040d64badb9dd6c77934d47

git at labs.omniti.com git at labs.omniti.com
Wed May 2 09:13:01 EDT 2012


Pushed by: jesus
The branch, master has been updated
       via  e88e9e38ef3322a56040d64badb9dd6c77934d47 (commit)
      from  d5e61dbf0c7e4b34195decd6f2b28faf0b3df9c1 (commit)

Summary of changes:
 src/noit_conf.c        |   12 +++++++--
 src/noit_conf_checks.c |   61 +++++++++++++++++++++++++++++-------------------
 src/noit_filters.c     |    5 +++-
 3 files changed, 50 insertions(+), 28 deletions(-)

Log:
commit e88e9e38ef3322a56040d64badb9dd6c77934d47
Author: Theo Schlossnagle <jesus at omniti.com>
Date:   Wed May 2 09:12:58 2012 -0400

    various memory leaks related so xmlXPathCastNodeToString and xmlGetNodePath

diff --git a/src/noit_conf.c b/src/noit_conf.c
index 5c38d39..197d5d8 100644
--- a/src/noit_conf.c
+++ b/src/noit_conf.c
@@ -1789,7 +1789,7 @@ noit_console_config_cd(noit_console_closure_t ncct,
                        int argc, char **argv,
                        noit_console_state_t *state, void *closure) {
   const char *err = "internal error";
-  char *path, xpath[1024];
+  char *path = NULL, xpath[1024];
   noit_conf_t_userdata_t *info;
   xmlXPathObjectPtr pobj = NULL;
   xmlXPathContextPtr xpath_ctxt = NULL, current_ctxt;
@@ -1846,13 +1846,19 @@ noit_console_config_cd(noit_console_closure_t ncct,
   free(info->path);
   if(!strcmp(path + 1, root_node_name))
     info->path = strdup("/");
-  else
-    info->path = strdup((char *)xmlGetNodePath(node) + 1 +
+  else {
+    char *xmlpath = (char *)xmlGetNodePath(node);
+    info->path = strdup(xmlpath + 1 +
                         strlen(root_node_name));
+    free(xmlpath);
+  }
+
+  if(path) free(path);
   if(pobj) xmlXPathFreeObject(pobj);
   if(closure) noit_console_state_pop(ncct, argc, argv, NULL, NULL);
   return 0;
  bad:
+  if(path) free(path);
   if(pobj) xmlXPathFreeObject(pobj);
   nc_printf(ncct, "%s [%s]\n", err, xpath);
   return -1;
diff --git a/src/noit_conf_checks.c b/src/noit_conf_checks.c
index 48ba68c..adb3154 100644
--- a/src/noit_conf_checks.c
+++ b/src/noit_conf_checks.c
@@ -231,7 +231,7 @@ noit_console_check(noit_console_closure_t ncct,
   int cnt;
   noit_conf_t_userdata_t *info;
   char xpath[1024], newuuid_str[37];
-  char *uuid_conf, *wanted;
+  char *uuid_conf = NULL, *wanted;
   uuid_t checkid;
   xmlXPathContextPtr xpath_ctxt = NULL;
   xmlXPathObjectPtr pobj = NULL;
@@ -302,8 +302,11 @@ noit_console_check(noit_console_closure_t ncct,
       nc_printf(ncct, "Partially successful, error setting some attributes\n");
 
   if(info) {
+    char *xmlpath;
     if(info->path) free(info->path);
-    info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit"));
+    xmlpath = (char *)xmlGetNodePath(node);
+    info->path = strdup(xmlpath + strlen("/noit"));
+    free(xmlpath);
     uuid_copy(info->current_check, checkid);
     if(argc > 1) refresh_subchecks(ncct, info);
     if(state) {
@@ -313,6 +316,7 @@ noit_console_check(noit_console_closure_t ncct,
     goto out;
   }
  out:
+  if(uuid_conf) free(uuid_conf);
   if(pobj) xmlXPathFreeObject(pobj);
   return 0;
 }
@@ -462,8 +466,10 @@ noit_console_show_check(noit_console_closure_t ncct,
 } while(0)
 
     if(!INHERIT(module, mnode, module)) module = NULL;
-    if(MYATTR(name, anode, value))
+    if(MYATTR(name, anode, value)) {
       nc_printf(ncct, " name: %s\n", value);
+      free(value);
+    }
     else
       nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]");
     nc_attr_show(ncct, "module", node, mnode, module);
@@ -698,9 +704,13 @@ noit_console_config_show(noit_console_closure_t ncct,
     if(!strcmp((char *)node->name, "check")) continue;
     if(node->children && node->children == xmlGetLastChild(node) &&
       xmlNodeIsText(node->children)) {
+      char *node_str, *xmlpath;
+      node_str = (char *)xmlXPathCastNodeToString(node->children);
+      xmlpath = (char *)xmlGetNodePath(node);
       if(!titled++) nc_printf(ncct, "== Section Settings ==\n");
-      nc_printf(ncct, "%s: %s\n", xmlGetNodePath(node) + cliplen,
-                xmlXPathCastNodeToString(node->children));
+      nc_printf(ncct, "%s: %s\n", xmlpath + cliplen, node_str);
+      free(xmlpath);
+      free(node_str);
     }
   }
   xmlXPathFreeObject(pobj);
@@ -742,15 +752,19 @@ noit_console_config_show(noit_console_closure_t ncct,
   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
   titled = 0;
   for(i=0; i<cnt; i++) {
+    char *xmlpath;
     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
     if(!strcmp((char *)node->name, "check")) continue;
     if(!strcmp((char *)node->name, "filterset")) continue;
-    if(!strcmp((char *)xmlGetNodePath(node) + cliplen, "config")) continue;
-    if(!(node->children && node->children == xmlGetLastChild(node) &&
-         xmlNodeIsText(node->children))) {
-      if(!titled++) nc_printf(ncct, "== Subsections ==\n");
-      nc_printf(ncct, "%s\n", xmlGetNodePath(node) + cliplen);
+    xmlpath = (char *)xmlGetNodePath(node);
+    if(strcmp(xmlpath + cliplen, "config")) {
+      if(!(node->children && node->children == xmlGetLastChild(node) &&
+           xmlNodeIsText(node->children))) {
+        if(!titled++) nc_printf(ncct, "== Subsections ==\n");
+        nc_printf(ncct, "%s\n", xmlpath + cliplen);
+      }
     }
+    free(xmlpath);
   }
 
   titled = 0;
@@ -772,28 +786,27 @@ noit_console_config_show(noit_console_closure_t ncct,
     else if(!strcmp((char *)node->name, "check")) {
       int busted = 1;
       xmlAttr *attr;
-      char *uuid_str = "undefined";
+      char *uuid_str = NULL;
+      uuid_t checkid;
 
       if(!titled++) nc_printf(ncct, "== Checks ==\n");
 
       for(attr=node->properties; attr; attr = attr->next) {
-        if(!strcmp((char *)attr->name, "uuid"))
+        if(!strcmp((char *)attr->name, "uuid")) {
           uuid_str = (char *)xmlXPathCastNodeToString(attr->children);
+          break;
+        }
       }
-      if(uuid_str) {
-        uuid_t checkid;
-        nc_printf(ncct, "check[@uuid=\"%s\"] ", uuid_str);
-        if(uuid_parse(uuid_str, checkid) == 0) {
-          noit_check_t *check;
-          check = noit_poller_lookup(checkid);
-          if(check) {
-            busted = 0;
-            nc_printf(ncct, "%s`%s`%s", check->target, check->module, check->name);
-          }
+      nc_printf(ncct, "check[@uuid=\"%s\"] ", uuid_str ? uuid_str : "undefined");
+      if(uuid_str && uuid_parse(uuid_str, checkid) == 0) {
+        noit_check_t *check;
+        check = noit_poller_lookup(checkid);
+        if(check) {
+          busted = 0;
+          nc_printf(ncct, "%s`%s`%s", check->target, check->module, check->name);
         }
       }
-      else
-        nc_printf(ncct, "%s ", xmlGetNodePath(node) + cliplen);
+      if(uuid_str) free(uuid_str);
       if(busted) nc_printf(ncct, "[check not in running system]");
       nc_write(ncct, "\n", 1);
     }
diff --git a/src/noit_filters.c b/src/noit_filters.c
index 0d6e114..e7fa486 100644
--- a/src/noit_filters.c
+++ b/src/noit_filters.c
@@ -448,8 +448,11 @@ noit_console_filter_configure(noit_console_closure_t ncct,
   }
 
   if(info) {
+    char *xmlpath = NULL;
     if(info->path) free(info->path);
-    info->path = strdup((char *)xmlGetNodePath(fsnode) + strlen("/noit"));
+    xmlpath = (char *)xmlGetNodePath(fsnode);
+    info->path = strdup(xmlpath + strlen("/noit"));
+    free(xmlpath);
     strlcpy(info->filter_name, argv[0], sizeof(info->filter_name));
     if(state) {
       noit_console_state_push_state(ncct, state);




hooks/post-receive
-- 
Reconnoiter


More information about the Reconnoiter-devel mailing list