From e36c6a31e64955a9d16ef105f4eb069565f0f1c7 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sun, 24 Mar 2024 22:44:53 +0100 Subject: [PATCH] commands: refactor memset Move memset() to the initialization function define_commands(). There is also not much point in clearing memory on command's exit so drop zeroing of ~2M of RAM. --- tools/command.c | 4 ++-- tools/lvmcmdline.c | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/command.c b/tools/command.c index 892e94f61..e30d2fa04 100644 --- a/tools/command.c +++ b/tools/command.c @@ -1451,6 +1451,8 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name) int skip = 0; int i; + memset(&commands, 0, sizeof(commands)); + if (run_name && !strcmp(run_name, "help")) run_name = NULL; @@ -3934,8 +3936,6 @@ int main(int argc, char *argv[]) {0, 0, 0, 0 } }; - memset(&commands, 0, sizeof(commands)); - if (!(stdout_buf = malloc(sz))) log_error("Failed to allocate stdout buffer; carrying on with default buffering."); else diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 06ec530a0..638577261 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -1342,7 +1342,6 @@ static void _unregister_commands(void) _cmdline.num_commands = 0; _cmdline.command_names = NULL; _cmdline.num_command_names = 0; - memset(&commands, 0, sizeof(commands)); } static int _command_name_compare(const void *on1, const void *on2) @@ -1363,8 +1362,6 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name) if (_cmdline.commands) return 1; - memset(&commands, 0, sizeof(commands)); - /* * populate commands[] array with command definitions * by parsing command-lines.in/command-lines-input.h