Skip to content

Commit

Permalink
Fix: fixed a memory leak in stonithd and crmd.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuusuke committed Mar 15, 2013
1 parent 0df3829 commit 8184e42
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crmd/te_callbacks.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ te_update_diff(const char *event, xmlNode * msg)
} }
} }


xmlXPathFreeObject(xpathObj);

} else if (xpathObj) { } else if (xpathObj) {
xmlXPathFreeObject(xpathObj); xmlXPathFreeObject(xpathObj);
} }
Expand Down
14 changes: 14 additions & 0 deletions fencing/commands.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -526,9 +526,16 @@ is_nodeid_required(xmlNode * xml)
} }
xpath = xpath_search(xml, "//parameter[@name='nodeid']"); xpath = xpath_search(xml, "//parameter[@name='nodeid']");
if (!xpath || xpath->nodesetval->nodeNr <= 0) { if (!xpath || xpath->nodesetval->nodeNr <= 0) {
if (xpath) {
xmlXPathFreeObject(xpath);
}
return FALSE; return FALSE;
} }


if (xpath) {
xmlXPathFreeObject(xpath);
}

return TRUE; return TRUE;
} }


Expand All @@ -547,6 +554,9 @@ get_on_target_actions(xmlNode * xml)
xpath = xpath_search(xml, "//action"); xpath = xpath_search(xml, "//action");


if (!xpath || !xpath->nodesetval) { if (!xpath || !xpath->nodesetval) {
if (xpath) {
xmlXPathFreeObject(xpath);
}
return NULL; return NULL;
} }


Expand All @@ -572,6 +582,10 @@ get_on_target_actions(xmlNode * xml)
} }
} }


if (xpath) {
xmlXPathFreeObject(xpath);
}

if (!strlen(actions)) { if (!strlen(actions)) {
free(actions); free(actions);
actions = NULL; actions = NULL;
Expand Down
12 changes: 12 additions & 0 deletions fencing/main.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ static bool filter_cib_device(const char *rsc_id, xmlNode *device)
return TRUE; return TRUE;
} }


if (rules) {
xmlXPathFreeObject(rules);
}

rule_path = g_strdup_printf("//" XML_CONS_TAG_RSC_LOCATION "[@rsc='%s']//"XML_TAG_RULE"[@"XML_RULE_ATTR_SCORE"='-INFINITY']//"XML_TAG_EXPRESSION, rsc_id); rule_path = g_strdup_printf("//" XML_CONS_TAG_RSC_LOCATION "[@rsc='%s']//"XML_TAG_RULE"[@"XML_RULE_ATTR_SCORE"='-INFINITY']//"XML_TAG_EXPRESSION, rsc_id);
crm_trace("Testing rule-based constraint: %s", rule_path); crm_trace("Testing rule-based constraint: %s", rule_path);
rules = xpath_search(local_cib, rule_path); rules = xpath_search(local_cib, rule_path);
Expand Down Expand Up @@ -567,6 +571,11 @@ static bool filter_cib_device(const char *rsc_id, xmlNode *device)
return TRUE; return TRUE;
} }
} }

if (rules) {
xmlXPathFreeObject(rules);
}

crm_trace("All done"); crm_trace("All done");
return FALSE; return FALSE;
} }
Expand Down Expand Up @@ -605,6 +614,8 @@ update_cib_device(xmlNode *device, gboolean force)
data = create_device_registration_xml(rsc_id, provider, agent, params); data = create_device_registration_xml(rsc_id, provider, agent, params);


stonith_device_register(data, NULL, TRUE); stonith_device_register(data, NULL, TRUE);
free_xml(data);
stonith_key_value_freeall(params, 1, 1);
} }
} }


Expand All @@ -625,6 +636,7 @@ register_cib_devices(xmlXPathObjectPtr xpathObj, gboolean force)
if (strcmp("stonith", standard) == 0) { if (strcmp("stonith", standard) == 0) {
char *device_path = g_strdup_printf("//%s[@id='%s']", XML_CIB_TAG_RESOURCE, rsc_id); char *device_path = g_strdup_printf("//%s[@id='%s']", XML_CIB_TAG_RESOURCE, rsc_id);
xmlNode *device = get_xpath_object(device_path, local_cib, LOG_ERR); xmlNode *device = get_xpath_object(device_path, local_cib, LOG_ERR);
free(device_path);
update_cib_device(device, force); update_cib_device(device, force);
} }
} }
Expand Down
13 changes: 13 additions & 0 deletions lib/fencing/st_client.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1081,6 +1081,10 @@ stonith_api_device_metadata(stonith_t * stonith, int call_options, const char *a
actions = getXpathResult(xpathObj, 0); actions = getXpathResult(xpathObj, 0);
} }


if (xpathObj) {
xmlXPathFreeObject(xpathObj);
}

/* Now fudge the metadata so that the start/stop actions appear */ /* Now fudge the metadata so that the start/stop actions appear */
xpathObj = xpath_search(xml, "//action[@name='stop']"); xpathObj = xpath_search(xml, "//action[@name='stop']");
if (xpathObj == NULL || xpathObj->nodesetval->nodeNr <= 0) { if (xpathObj == NULL || xpathObj->nodesetval->nodeNr <= 0) {
Expand All @@ -1095,6 +1099,10 @@ stonith_api_device_metadata(stonith_t * stonith, int call_options, const char *a
crm_xml_add(tmp, "timeout", "20s"); crm_xml_add(tmp, "timeout", "20s");
} }


if (xpathObj) {
xmlXPathFreeObject(xpathObj);
}

/* Now fudge the metadata so that the port isn't required in the configuration */ /* Now fudge the metadata so that the port isn't required in the configuration */
xpathObj = xpath_search(xml, "//parameter[@name='port']"); xpathObj = xpath_search(xml, "//parameter[@name='port']");
if (xpathObj && xpathObj->nodesetval->nodeNr > 0) { if (xpathObj && xpathObj->nodesetval->nodeNr > 0) {
Expand All @@ -1104,6 +1112,9 @@ stonith_api_device_metadata(stonith_t * stonith, int call_options, const char *a
crm_xml_add(tmp, "required", "0"); crm_xml_add(tmp, "required", "0");
} }


if (xpathObj) {
xmlXPathFreeObject(xpathObj);
}
free(buffer); free(buffer);
buffer = dump_xml_formatted(xml); buffer = dump_xml_formatted(xml);
free_xml(xml); free_xml(xml);
Expand Down Expand Up @@ -1242,6 +1253,8 @@ stonith_api_query(stonith_t * stonith, int call_options, const char *target,
crm_info("%s[%d] = %s", "//@agent", lpc, xmlGetNodePath(match)); crm_info("%s[%d] = %s", "//@agent", lpc, xmlGetNodePath(match));
*devices = stonith_key_value_add(*devices, NULL, crm_element_value(match, XML_ATTR_ID)); *devices = stonith_key_value_add(*devices, NULL, crm_element_value(match, XML_ATTR_ID));
} }

xmlXPathFreeObject(xpathObj);
} }


free_xml(output); free_xml(output);
Expand Down

0 comments on commit 8184e42

Please sign in to comment.