Changeset e88e9e38ef3322a56040d64badb9dd6c77934d47

Show
Ignore:
Timestamp:
05/02/12 13:12:58 (2 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1335964378 -0400
git-parent:

[d5e61dbf0c7e4b34195decd6f2b28faf0b3df9c1]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1335964378 -0400
Message:

various memory leaks related so xmlXPathCastNodeToString and xmlGetNodePath

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_conf.c

    rd5db0b8 re88e9e3  
    17901790                       noit_console_state_t *state, void *closure) { 
    17911791  const char *err = "internal error"; 
    1792   char *path, xpath[1024]; 
     1792  char *path = NULL, xpath[1024]; 
    17931793  noit_conf_t_userdata_t *info; 
    17941794  xmlXPathObjectPtr pobj = NULL; 
     
    18471847  if(!strcmp(path + 1, root_node_name)) 
    18481848    info->path = strdup("/"); 
    1849   else 
    1850     info->path = strdup((char *)xmlGetNodePath(node) + 1 + 
     1849  else { 
     1850    char *xmlpath = (char *)xmlGetNodePath(node); 
     1851    info->path = strdup(xmlpath + 1 + 
    18511852                        strlen(root_node_name)); 
     1853    free(xmlpath); 
     1854  } 
     1855 
     1856  if(path) free(path); 
    18521857  if(pobj) xmlXPathFreeObject(pobj); 
    18531858  if(closure) noit_console_state_pop(ncct, argc, argv, NULL, NULL); 
    18541859  return 0; 
    18551860 bad: 
     1861  if(path) free(path); 
    18561862  if(pobj) xmlXPathFreeObject(pobj); 
    18571863  nc_printf(ncct, "%s [%s]\n", err, xpath); 
  • src/noit_conf_checks.c

    r5fd1894 re88e9e3  
    232232  noit_conf_t_userdata_t *info; 
    233233  char xpath[1024], newuuid_str[37]; 
    234   char *uuid_conf, *wanted; 
     234  char *uuid_conf = NULL, *wanted; 
    235235  uuid_t checkid; 
    236236  xmlXPathContextPtr xpath_ctxt = NULL; 
     
    303303 
    304304  if(info) { 
     305    char *xmlpath; 
    305306    if(info->path) free(info->path); 
    306     info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit")); 
     307    xmlpath = (char *)xmlGetNodePath(node); 
     308    info->path = strdup(xmlpath + strlen("/noit")); 
     309    free(xmlpath); 
    307310    uuid_copy(info->current_check, checkid); 
    308311    if(argc > 1) refresh_subchecks(ncct, info); 
     
    314317  } 
    315318 out: 
     319  if(uuid_conf) free(uuid_conf); 
    316320  if(pobj) xmlXPathFreeObject(pobj); 
    317321  return 0; 
     
    463467 
    464468    if(!INHERIT(module, mnode, module)) module = NULL; 
    465     if(MYATTR(name, anode, value)) 
     469    if(MYATTR(name, anode, value)) { 
    466470      nc_printf(ncct, " name: %s\n", value); 
     471      free(value); 
     472    } 
    467473    else 
    468474      nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]"); 
     
    699705    if(node->children && node->children == xmlGetLastChild(node) && 
    700706      xmlNodeIsText(node->children)) { 
     707      char *node_str, *xmlpath; 
     708      node_str = (char *)xmlXPathCastNodeToString(node->children); 
     709      xmlpath = (char *)xmlGetNodePath(node); 
    701710      if(!titled++) nc_printf(ncct, "== Section Settings ==\n"); 
    702       nc_printf(ncct, "%s: %s\n", xmlGetNodePath(node) + cliplen, 
    703                 xmlXPathCastNodeToString(node->children)); 
     711      nc_printf(ncct, "%s: %s\n", xmlpath + cliplen, node_str); 
     712      free(xmlpath); 
     713      free(node_str); 
    704714    } 
    705715  } 
     
    743753  titled = 0; 
    744754  for(i=0; i<cnt; i++) { 
     755    char *xmlpath; 
    745756    node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); 
    746757    if(!strcmp((char *)node->name, "check")) continue; 
    747758    if(!strcmp((char *)node->name, "filterset")) continue; 
    748     if(!strcmp((char *)xmlGetNodePath(node) + cliplen, "config")) continue; 
    749     if(!(node->children && node->children == xmlGetLastChild(node) && 
    750          xmlNodeIsText(node->children))) { 
    751       if(!titled++) nc_printf(ncct, "== Subsections ==\n"); 
    752       nc_printf(ncct, "%s\n", xmlGetNodePath(node) + cliplen); 
    753     } 
     759    xmlpath = (char *)xmlGetNodePath(node); 
     760    if(strcmp(xmlpath + cliplen, "config")) { 
     761      if(!(node->children && node->children == xmlGetLastChild(node) && 
     762           xmlNodeIsText(node->children))) { 
     763        if(!titled++) nc_printf(ncct, "== Subsections ==\n"); 
     764        nc_printf(ncct, "%s\n", xmlpath + cliplen); 
     765      } 
     766    } 
     767    free(xmlpath); 
    754768  } 
    755769 
     
    773787      int busted = 1; 
    774788      xmlAttr *attr; 
    775       char *uuid_str = "undefined"; 
     789      char *uuid_str = NULL; 
     790      uuid_t checkid; 
    776791 
    777792      if(!titled++) nc_printf(ncct, "== Checks ==\n"); 
    778793 
    779794      for(attr=node->properties; attr; attr = attr->next) { 
    780         if(!strcmp((char *)attr->name, "uuid")) 
     795        if(!strcmp((char *)attr->name, "uuid")) { 
    781796          uuid_str = (char *)xmlXPathCastNodeToString(attr->children); 
    782       } 
    783       if(uuid_str) { 
    784         uuid_t checkid; 
    785         nc_printf(ncct, "check[@uuid=\"%s\"] ", uuid_str); 
    786         if(uuid_parse(uuid_str, checkid) == 0) { 
    787           noit_check_t *check; 
    788           check = noit_poller_lookup(checkid); 
    789           if(check) { 
    790             busted = 0; 
    791             nc_printf(ncct, "%s`%s`%s", check->target, check->module, check->name); 
    792           } 
     797          break; 
    793798        } 
    794799      } 
    795       else 
    796         nc_printf(ncct, "%s ", xmlGetNodePath(node) + cliplen); 
     800      nc_printf(ncct, "check[@uuid=\"%s\"] ", uuid_str ? uuid_str : "undefined"); 
     801      if(uuid_str && uuid_parse(uuid_str, checkid) == 0) { 
     802        noit_check_t *check; 
     803        check = noit_poller_lookup(checkid); 
     804        if(check) { 
     805          busted = 0; 
     806          nc_printf(ncct, "%s`%s`%s", check->target, check->module, check->name); 
     807        } 
     808      } 
     809      if(uuid_str) free(uuid_str); 
    797810      if(busted) nc_printf(ncct, "[check not in running system]"); 
    798811      nc_write(ncct, "\n", 1); 
  • src/noit_filters.c

    r66dbd3e re88e9e3  
    449449 
    450450  if(info) { 
     451    char *xmlpath = NULL; 
    451452    if(info->path) free(info->path); 
    452     info->path = strdup((char *)xmlGetNodePath(fsnode) + strlen("/noit")); 
     453    xmlpath = (char *)xmlGetNodePath(fsnode); 
     454    info->path = strdup(xmlpath + strlen("/noit")); 
     455    free(xmlpath); 
    453456    strlcpy(info->filter_name, argv[0], sizeof(info->filter_name)); 
    454457    if(state) {