Skip to content

Commit e16e512

Browse files
author
Ken Gaillot
authored
Merge pull request #2016 from clumens/leaks
Fix memory leaks
2 parents f0be039 + 2f9c7bb commit e16e512

6 files changed

Lines changed: 35 additions & 8 deletions

File tree

lib/common/cmdline.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ pcmk__add_arg_group(GOptionContext *context, const char *name,
142142
gchar **
143143
pcmk__cmdline_preproc(char **argv, const char *special) {
144144
gchar **retval = NULL;
145-
GPtrArray *arr = g_ptr_array_new();
145+
GPtrArray *arr = NULL;
146146
bool saw_dash_dash = false;
147147

148148
if (argv == NULL) {
149149
return retval;
150150
}
151151

152+
arr = g_ptr_array_new();
153+
152154
for (int i = 0; argv[i] != NULL; i++) {
153155
/* If this is the first time we saw "--" in the command line, set
154156
* a flag so we know to just copy everything after it over. We also

tools/crm_diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ main(int argc, char **argv)
332332
}
333333

334334
if (optind > argc) {
335-
fprintf(stderr, "%s", g_option_context_get_help(context, TRUE, NULL));
335+
char *help = g_option_context_get_help(context, TRUE, NULL);
336+
337+
fprintf(stderr, "%s", help);
338+
free(help);
336339
rc = CRM_EX_USAGE;
337340
goto done;
338341
}

tools/crm_mon.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static unsigned int show;
6363
static mon_output_format_t output_format = mon_output_unset;
6464

6565
/* other globals */
66+
static GIOChannel *io_channel = NULL;
6667
static GMainLoop *mainloop = NULL;
6768
static guint timer_id = 0;
6869
static mainloop_timer_t *refresh_timer = NULL;
@@ -1377,14 +1378,20 @@ main(int argc, char **argv)
13771378
if (ncurses_winch_handler == SIG_DFL ||
13781379
ncurses_winch_handler == SIG_IGN || ncurses_winch_handler == SIG_ERR)
13791380
ncurses_winch_handler = NULL;
1380-
g_io_add_watch(g_io_channel_unix_new(STDIN_FILENO), G_IO_IN, detect_user_input, NULL);
1381+
1382+
io_channel = g_io_channel_unix_new(STDIN_FILENO);
1383+
g_io_add_watch(io_channel, G_IO_IN, detect_user_input, NULL);
13811384
}
13821385
#endif
13831386
refresh_trigger = mainloop_add_trigger(G_PRIORITY_LOW, mon_refresh_display, NULL);
13841387

13851388
g_main_loop_run(mainloop);
13861389
g_main_loop_unref(mainloop);
13871390

1391+
if (io_channel != NULL) {
1392+
g_io_channel_shutdown(io_channel, TRUE, NULL);
1393+
}
1394+
13881395
crm_info("Exiting %s", crm_system_name);
13891396

13901397
return clean_up(CRM_EX_OK);
@@ -2119,7 +2126,10 @@ clean_up(crm_exit_t exit_code)
21192126
* message.
21202127
*/
21212128
if (exit_code == CRM_EX_USAGE && (output_format == mon_output_console || output_format == mon_output_plain)) {
2122-
fprintf(stderr, "%s", g_option_context_get_help(context, TRUE, NULL));
2129+
char *help = g_option_context_get_help(context, TRUE, NULL);
2130+
2131+
fprintf(stderr, "%s", help);
2132+
free(help);
21232133
}
21242134

21252135
pcmk__free_arg_context(context);

tools/crm_node.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,10 @@ main(int argc, char **argv)
623623
}
624624

625625
if (optind > argc || options.command == 0) {
626-
fprintf(stderr, "%s", g_option_context_get_help(context, TRUE, NULL));
626+
char *help = g_option_context_get_help(context, TRUE, NULL);
627+
628+
fprintf(stderr, "%s", help);
629+
free(help);
627630
exit_code = CRM_EX_USAGE;
628631
goto done;
629632
}

tools/crm_rule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ main(int argc, char **argv)
238238
}
239239

240240
if (optind > argc) {
241-
CMD_ERR("%s", g_option_context_get_help(context, TRUE, NULL));
241+
char *help = g_option_context_get_help(context, TRUE, NULL);
242+
243+
CMD_ERR("%s", help);
244+
free(help);
242245
exit_code = CRM_EX_USAGE;
243246
goto bail;
244247
}

tools/stonith_admin.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,20 @@ main(int argc, char **argv)
473473
}
474474

475475
if (optind > argc || action == 0) {
476-
out->err(out, "%s", g_option_context_get_help(context, TRUE, NULL));
476+
char *help = g_option_context_get_help(context, TRUE, NULL);
477+
478+
out->err(out, "%s", help);
479+
free(help);
477480
exit_code = CRM_EX_USAGE;
478481
goto done;
479482
}
480483

481484
if (required_agent && options.agent == NULL) {
485+
char *help = g_option_context_get_help(context, TRUE, NULL);
486+
482487
out->err(out, "Please specify an agent to query using -a,--agent [value]");
483-
out->err(out, "%s", g_option_context_get_help(context, TRUE, NULL));
488+
out->err(out, "%s", help);
489+
free(help);
484490
exit_code = CRM_EX_USAGE;
485491
goto done;
486492
}

0 commit comments

Comments
 (0)