Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP4:Update
pacemaker
pacemaker#3394-0002-Low-libpacemaker-Correctly-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File pacemaker#3394-0002-Low-libpacemaker-Correctly-free-graphs-and-synapses.patch of Package pacemaker
From e725721056920d2480bc488688af51768969ba22 Mon Sep 17 00:00:00 2001 From: Reid Wahl <nrwahl@protonmail.com> Date: Wed, 20 Mar 2024 17:40:18 -0700 Subject: [PATCH 2/2] Low: libpacemaker: Correctly free graphs and synapses Memory leak found by Cppcheck. Signed-off-by: Reid Wahl <nrwahl@protonmail.com> --- lib/pacemaker/pcmk_graph_consumer.c | 136 ++++++++++++++-------------- 1 file changed, 68 insertions(+), 68 deletions(-) Index: pacemaker-2.1.2+20211124.ada5c3b36/lib/pacemaker/pcmk_graph_consumer.c =================================================================== --- pacemaker-2.1.2+20211124.ada5c3b36.orig/lib/pacemaker/pcmk_graph_consumer.c +++ pacemaker-2.1.2+20211124.ada5c3b36/lib/pacemaker/pcmk_graph_consumer.c @@ -21,6 +21,66 @@ /* + * Functions for freeing transition graph objects + */ + +/*! + * \internal + * \brief Free a transition graph action object + * + * \param[in,out] user_data Action to free + */ +static void +free_graph_action(gpointer user_data) +{ + crm_action_t *action = user_data; + + if ((action->timer != NULL) && (action->timer->source_id != 0)) { + crm_warn("Cancelling timer for graph action %d", action->id); + g_source_remove(action->timer->source_id); + } + if (action->params != NULL) { + g_hash_table_destroy(action->params); + } + free_xml(action->xml); + free(action->timer); + free(action); +} + +/*! + * \internal + * \brief Free a transition graph synapse object + * + * \param[in,out] user_data Synapse to free + */ +static void +free_graph_synapse(gpointer user_data) +{ + synapse_t *synapse = user_data; + + g_list_free_full(synapse->actions, free_graph_action); + g_list_free_full(synapse->inputs, free_graph_action); + free(synapse); +} + +/*! + * \internal + * \brief Free a transition graph object + * + * \param[in,out] graph Transition graph to free + */ +void +pcmk__free_graph(crm_graph_t *graph) +{ + if (graph != NULL) { + g_list_free_full(graph->synapses, free_graph_synapse); + free(graph->source); + free(graph); + } +} + + +/* * Functions for updating graph */ @@ -575,8 +634,8 @@ unpack_synapse(crm_graph_t *new_graph, x value = crm_element_value(xml_synapse, XML_CIB_ATTR_PRIORITY); pcmk__scan_min_int(value, &(new_synapse->priority), 0); - CRM_CHECK(new_synapse->id >= 0, free(new_synapse); - return NULL); + CRM_CHECK(new_synapse->id >= 0, + free_graph_synapse((gpointer) new_synapse); return NULL); new_graph->num_synapses++; @@ -671,7 +730,7 @@ pcmk__unpack_graph(xmlNode *xml_graph, c new_graph->source = strdup((reference == NULL)? "unknown" : reference); if (new_graph->source == NULL) { - free(new_graph); + pcmk__free_graph(new_graph); return NULL; } @@ -684,13 +743,13 @@ pcmk__unpack_graph(xmlNode *xml_graph, c // Parse top-level attributes from <transition_graph> if (xml_graph != NULL) { t_id = crm_element_value(xml_graph, "transition_id"); - CRM_CHECK(t_id != NULL, free(new_graph); - return NULL); + CRM_CHECK(t_id != NULL, + pcmk__free_graph(new_graph); return NULL); pcmk__scan_min_int(t_id, &(new_graph->id), -1); time = crm_element_value(xml_graph, "cluster-delay"); - CRM_CHECK(time != NULL, free(new_graph); - return NULL); + CRM_CHECK(time != NULL, + pcmk__free_graph(new_graph); return NULL); new_graph->network_delay = crm_parse_interval_spec(time); time = crm_element_value(xml_graph, "stonith-timeout"); @@ -732,66 +791,6 @@ pcmk__unpack_graph(xmlNode *xml_graph, c } -/* - * Functions for freeing transition graph objects - */ - -/*! - * \internal - * \brief Free a transition graph action object - * - * \param[in] user_data Action to free - */ -static void -free_graph_action(gpointer user_data) -{ - crm_action_t *action = user_data; - - if ((action->timer != NULL) && (action->timer->source_id != 0)) { - crm_warn("Cancelling timer for graph action %d", action->id); - g_source_remove(action->timer->source_id); - } - if (action->params != NULL) { - g_hash_table_destroy(action->params); - } - free_xml(action->xml); - free(action->timer); - free(action); -} - -/*! - * \internal - * \brief Free a transition graph synapse object - * - * \param[in] user_data Synapse to free - */ -static void -free_graph_synapse(gpointer user_data) -{ - synapse_t *synapse = user_data; - - g_list_free_full(synapse->actions, free_graph_action); - g_list_free_full(synapse->inputs, free_graph_action); - free(synapse); -} - -/*! - * \internal - * \brief Free a transition graph object - * - * \param[in] graph Transition graph to free - */ -void -pcmk__free_graph(crm_graph_t *graph) -{ - if (graph != NULL) { - g_list_free_full(graph->synapses, free_graph_synapse); - free(graph->source); - free(graph); - } -} - - /* * Other transition graph utilities */
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor