Skip to content

Commit 4750fcf

Browse files
committed
API: libpacemaker: pcmk_free_injections() calls free instead of g_free
If you're creating or modifying the GList fields of a pcmk_injections_t object manually, be sure to allocate the list elements using the malloc() family of allocators. Previously, pcmk_free_injections() assumed that the list elements had been allocated using the g_malloc() family of allocators from GLib. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 241c6f5 commit 4750fcf

3 files changed

Lines changed: 48 additions & 34 deletions

File tree

include/pacemaker.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,33 @@ enum pcmk_sim_flags {
5050
/*!
5151
* \brief Synthetic cluster events that can be injected into the cluster
5252
* for running simulations.
53+
*
54+
* \note This struct should typically be freed using \c pcmk_free_injections().
5355
*/
5456
typedef struct {
55-
/*! A list of node names (gchar *) to simulate bringing online */
57+
/*! A list of node names (char *) to simulate bringing online */
5658
GList *node_up;
57-
/*! A list of node names (gchar *) to simulate bringing offline */
59+
/*! A list of node names (char *) to simulate bringing offline */
5860
GList *node_down;
59-
/*! A list of node names (gchar *) to simulate failing */
61+
/*! A list of node names (char *) to simulate failing */
6062
GList *node_fail;
61-
/*! A list of operations (gchar *) to inject. The format of these strings
63+
/*! A list of operations (char *) to inject. The format of these strings
6264
* is described in the "Operation Specification" section of crm_simulate
6365
* help output.
6466
*/
6567
GList *op_inject;
66-
/*! A list of operations (gchar *) that should return a given error code
68+
/*! A list of operations (char *) that should return a given error code
6769
* if they fail. The format of these strings is described in the
6870
* "Operation Specification" section of crm_simulate help output.
6971
*/
7072
GList *op_fail;
71-
/*! A list of tickets (gchar *) to simulate granting */
73+
/*! A list of tickets (char *) to simulate granting */
7274
GList *ticket_grant;
73-
/*! A list of tickets (gchar *) to simulate revoking */
75+
/*! A list of tickets (char *) to simulate revoking */
7476
GList *ticket_revoke;
75-
/*! A list of tickets (gchar *) to simulate putting on standby */
77+
/*! A list of tickets (char *) to simulate putting on standby */
7678
GList *ticket_standby;
77-
/*! A list of tickets (gchar *) to simulate activating */
79+
/*! A list of tickets (char *) to simulate activating */
7880
GList *ticket_activate;
7981
/*! Does the cluster have an active watchdog device? */
8082
char *watchdog;

lib/pacemaker/pcmk_injections.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib,
685685
}
686686

687687
for (iter = injections->node_up; iter != NULL; iter = iter->next) {
688-
const char *node = (const char *) iter->data;
688+
const char *node = iter->data;
689689

690690
out->message(out, "inject-modify-node", "Online", node);
691691

@@ -698,7 +698,7 @@ pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib,
698698
}
699699

700700
for (iter = injections->node_down; iter != NULL; iter = iter->next) {
701-
const char *node = (const char *) iter->data;
701+
const char *node = iter->data;
702702
char *xpath = NULL;
703703

704704
out->message(out, "inject-modify-node", "Offline", node);
@@ -726,7 +726,7 @@ pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib,
726726
}
727727

728728
for (iter = injections->node_fail; iter != NULL; iter = iter->next) {
729-
const char *node = (const char *) iter->data;
729+
const char *node = iter->data;
730730

731731
out->message(out, "inject-modify-node", "Failing", node);
732732

@@ -740,7 +740,7 @@ pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib,
740740
}
741741

742742
for (iter = injections->ticket_grant; iter != NULL; iter = iter->next) {
743-
const char *ticket_id = (const char *) iter->data;
743+
const char *ticket_id = iter->data;
744744

745745
out->message(out, "inject-modify-ticket", "Granting", ticket_id);
746746

@@ -749,7 +749,7 @@ pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib,
749749
}
750750

751751
for (iter = injections->ticket_revoke; iter != NULL; iter = iter->next) {
752-
const char *ticket_id = (const char *) iter->data;
752+
const char *ticket_id = iter->data;
753753

754754
out->message(out, "inject-modify-ticket", "Revoking", ticket_id);
755755

@@ -759,7 +759,7 @@ pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib,
759759
}
760760

761761
for (iter = injections->ticket_standby; iter != NULL; iter = iter->next) {
762-
const char *ticket_id = (const char *) iter->data;
762+
const char *ticket_id = iter->data;
763763

764764
out->message(out, "inject-modify-ticket", "Standby", ticket_id);
765765

@@ -768,7 +768,7 @@ pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib,
768768
}
769769

770770
for (iter = injections->ticket_activate; iter != NULL; iter = iter->next) {
771-
const char *ticket_id = (const char *) iter->data;
771+
const char *ticket_id = iter->data;
772772

773773
out->message(out, "inject-modify-ticket", "Activating", ticket_id);
774774

@@ -792,15 +792,15 @@ pcmk_free_injections(pcmk_injections_t *injections)
792792
return;
793793
}
794794

795-
g_list_free_full(injections->node_up, g_free);
796-
g_list_free_full(injections->node_down, g_free);
797-
g_list_free_full(injections->node_fail, g_free);
798-
g_list_free_full(injections->op_fail, g_free);
799-
g_list_free_full(injections->op_inject, g_free);
800-
g_list_free_full(injections->ticket_grant, g_free);
801-
g_list_free_full(injections->ticket_revoke, g_free);
802-
g_list_free_full(injections->ticket_standby, g_free);
803-
g_list_free_full(injections->ticket_activate, g_free);
795+
g_list_free_full(injections->node_up, free);
796+
g_list_free_full(injections->node_down, free);
797+
g_list_free_full(injections->node_fail, free);
798+
g_list_free_full(injections->op_fail, free);
799+
g_list_free_full(injections->op_inject, free);
800+
g_list_free_full(injections->ticket_grant, free);
801+
g_list_free_full(injections->ticket_revoke, free);
802+
g_list_free_full(injections->ticket_standby, free);
803+
g_list_free_full(injections->ticket_activate, free);
804804
free(injections->quorum);
805805
free(injections->watchdog);
806806

tools/crm_simulate.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,17 @@ static gboolean
114114
node_down_cb(const char *option_name, const char *optarg, void *data,
115115
GError **error)
116116
{
117-
options.injections->node_down = g_list_append(options.injections->node_down, g_strdup(optarg));
117+
options.injections->node_down = g_list_append(options.injections->node_down,
118+
pcmk__str_copy(optarg));
118119
return TRUE;
119120
}
120121

121122
static gboolean
122123
node_fail_cb(const char *option_name, const char *optarg, void *data,
123124
GError **error)
124125
{
125-
options.injections->node_fail = g_list_append(options.injections->node_fail, g_strdup(optarg));
126+
options.injections->node_fail = g_list_append(options.injections->node_fail,
127+
pcmk__str_copy(optarg));
126128
return TRUE;
127129
}
128130

@@ -131,7 +133,8 @@ node_up_cb(const char *option_name, const char *optarg, void *data,
131133
GError **error)
132134
{
133135
pcmk__simulate_node_config = true;
134-
options.injections->node_up = g_list_append(options.injections->node_up, g_strdup(optarg));
136+
options.injections->node_up = g_list_append(options.injections->node_up,
137+
pcmk__str_copy(optarg));
135138
return TRUE;
136139
}
137140

@@ -140,15 +143,17 @@ op_fail_cb(const char *option_name, const char *optarg, void *data,
140143
GError **error)
141144
{
142145
options.flags |= pcmk_sim_process | pcmk_sim_simulate;
143-
options.injections->op_fail = g_list_append(options.injections->op_fail, g_strdup(optarg));
146+
options.injections->op_fail = g_list_append(options.injections->op_fail,
147+
pcmk__str_copy(optarg));
144148
return TRUE;
145149
}
146150

147151
static gboolean
148152
op_inject_cb(const char *option_name, const char *optarg, void *data,
149153
GError **error)
150154
{
151-
options.injections->op_inject = g_list_append(options.injections->op_inject, g_strdup(optarg));
155+
options.injections->op_inject = g_list_append(options.injections->op_inject,
156+
pcmk__str_copy(optarg));
152157
return TRUE;
153158
}
154159

@@ -214,31 +219,38 @@ static gboolean
214219
ticket_activate_cb(const char *option_name, const char *optarg, void *data,
215220
GError **error)
216221
{
217-
options.injections->ticket_activate = g_list_append(options.injections->ticket_activate, g_strdup(optarg));
222+
options.injections->ticket_activate =
223+
g_list_append(options.injections->ticket_activate,
224+
pcmk__str_copy(optarg));
218225
return TRUE;
219226
}
220227

221228
static gboolean
222229
ticket_grant_cb(const char *option_name, const char *optarg, void *data,
223230
GError **error)
224231
{
225-
options.injections->ticket_grant = g_list_append(options.injections->ticket_grant, g_strdup(optarg));
232+
options.injections->ticket_grant =
233+
g_list_append(options.injections->ticket_grant, pcmk__str_copy(optarg));
226234
return TRUE;
227235
}
228236

229237
static gboolean
230238
ticket_revoke_cb(const char *option_name, const char *optarg, void *data,
231239
GError **error)
232240
{
233-
options.injections->ticket_revoke = g_list_append(options.injections->ticket_revoke, g_strdup(optarg));
241+
options.injections->ticket_revoke =
242+
g_list_append(options.injections->ticket_revoke,
243+
pcmk__str_copy(optarg));
234244
return TRUE;
235245
}
236246

237247
static gboolean
238248
ticket_standby_cb(const char *option_name, const char *optarg, void *data,
239249
GError **error)
240250
{
241-
options.injections->ticket_standby = g_list_append(options.injections->ticket_standby, g_strdup(optarg));
251+
options.injections->ticket_standby =
252+
g_list_append(options.injections->ticket_standby,
253+
pcmk__str_copy(optarg));
242254
return TRUE;
243255
}
244256

0 commit comments

Comments
 (0)