Skip to content

Commit 6feb036

Browse files
committed
Fix: libcrmcommon: Add pcmk__unregister_formats.
This functions frees the hash table previously constructed by pcmk__register_formats and also frees the strings that are the keys. This should be called at program termination.
1 parent 949368d commit 6feb036

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

daemons/schedulerd/pacemaker-schedulerd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ main(int argc, char **argv)
345345
g_main_loop_run(mainloop);
346346

347347
pe_free_working_set(sched_data_set);
348+
pcmk__unregister_formats();
348349
crm_info("Exiting %s", crm_system_name);
349350
crm_exit(CRM_EX_OK);
350351
}

include/crm/common/output.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,14 @@ pcmk__register_format(GOptionGroup *group, const char *name,
512512
void
513513
pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table);
514514

515+
/*!
516+
* \internal
517+
* \brief Unregister a previously registered table of custom formatting
518+
* functions and destroy the internal data structures associated with them.
519+
*/
520+
void
521+
pcmk__unregister_formats(void);
522+
515523
/*!
516524
* \internal
517525
* \brief Register a function to handle a custom message.

lib/common/output.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pcmk__register_format(GOptionGroup *group, const char *name,
8181
}
8282

8383
if (formatters == NULL) {
84-
formatters = g_hash_table_new_full(crm_str_hash, g_str_equal, NULL, NULL);
84+
formatters = g_hash_table_new_full(crm_str_hash, g_str_equal, free, NULL);
8585
}
8686

8787
if (options != NULL && group != NULL) {
@@ -105,6 +105,13 @@ pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *formats) {
105105
}
106106
}
107107

108+
void
109+
pcmk__unregister_formats() {
110+
if (formatters != NULL) {
111+
g_hash_table_destroy(formatters);
112+
}
113+
}
114+
108115
int
109116
pcmk__call_message(pcmk__output_t *out, const char *message_id, ...) {
110117
va_list args;

tools/crm_mon.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,7 @@ clean_up(crm_exit_t exit_code)
21572157
}
21582158

21592159
pcmk__output_free(out);
2160+
pcmk__unregister_formats();
21602161
}
21612162

21622163
crm_exit(exit_code);

0 commit comments

Comments
 (0)