1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

commands: use dm wrappers for malloc/free

This commit is contained in:
David Teigland 2017-02-15 15:49:18 -06:00
parent 6a5c9ba349
commit 81c0ed9fc6

View File

@ -45,6 +45,10 @@ do { \
printf(fmt "\n", ##args); \
} while (0)
#define dm_malloc malloc
#define dm_free free
#define dm_strdup strdup
/* needed to include args.h */
#define ARG_COUNTABLE 0x00000001
#define ARG_GROUPABLE 0x00000002
@ -680,7 +684,7 @@ static void set_opt_def(struct command *cmd, char *str, struct arg_def *def)
def->num = (uint64_t)atoi(name);
if (val_enum == conststr_VAL)
def->str = strdup(name);
def->str = dm_strdup(name);
if (val_enum == lv_VAL) {
if (strstr(name, "_"))
@ -714,7 +718,7 @@ static void add_oo_definition_line(const char *name, const char *line)
char *start;
oo = &oo_lines[oo_line_count++];
oo->name = strdup(name);
oo->name = dm_strdup(name);
if ((colon = strstr(oo->name, ":")))
*colon = '\0';
@ -724,7 +728,7 @@ static void add_oo_definition_line(const char *name, const char *line)
}
start = strstr(line, ":") + 2;
oo->line = strdup(start);
oo->line = dm_strdup(start);
}
/* Support OO_FOO: continuing on multiple lines. */
@ -742,7 +746,7 @@ static void append_oo_definition_line(const char *new_line)
/* +2 = 1 space between old and new + 1 terminating \0 */
len = strlen(old_line) + strlen(new_line) + 2;
line = malloc(len);
line = dm_malloc(len);
if (!line) {
log_error("Parsing command defs: no memory");
exit(EXIT_FAILURE);
@ -753,7 +757,7 @@ static void append_oo_definition_line(const char *new_line)
strcat(line, " ");
strcat(line, new_line);
free(oo->line);
dm_free(oo->line);
oo->line = line;
}
@ -800,12 +804,12 @@ static void include_optional_opt_args(struct command *cmd, const char *str)
exit(EXIT_FAILURE);
}
if (!(line = strdup(oo_line)))
if (!(line = dm_strdup(oo_line)))
exit(EXIT_FAILURE);
split_line(line, &line_argc, line_argv, ' ');
add_optional_opt_line(cmd, line_argc, line_argv);
free(line);
dm_free(line);
}
/*
@ -1027,12 +1031,12 @@ static void include_required_opt_args(struct command *cmd, char *str)
exit(EXIT_FAILURE);
}
if (!(line = strdup(oo_line)))
if (!(line = dm_strdup(oo_line)))
exit(EXIT_FAILURE);
split_line(line, &line_argc, line_argv, ' ');
add_required_opt_line(cmd, line_argc, line_argv);
free(line);
dm_free(line);
}
/* Process what follows command_name, which are required opt/pos args. */
@ -1128,7 +1132,7 @@ static void add_rule(struct command *cmd, char *line)
else if (!strncmp(arg, "--", 2)) {
if (!rule->opts) {
if (!(rule->opts = malloc(MAX_RULE_OPTS * sizeof(int)))) {
if (!(rule->opts = dm_malloc(MAX_RULE_OPTS * sizeof(int)))) {
log_error("Parsing command defs: no mem");
exit(EXIT_FAILURE);
}
@ -1136,7 +1140,7 @@ static void add_rule(struct command *cmd, char *line)
}
if (!rule->check_opts) {
if (!(rule->check_opts = malloc(MAX_RULE_OPTS * sizeof(int)))) {
if (!(rule->check_opts = dm_malloc(MAX_RULE_OPTS * sizeof(int)))) {
log_error("Parsing command defs: no mem");
exit(EXIT_FAILURE);
}
@ -1343,7 +1347,7 @@ int define_commands(char *run_name)
cmd = &commands[cmd_count];
cmd->command_index = cmd_count;
cmd_count++;
cmd->name = strdup(name);
cmd->name = dm_strdup(name);
if (run_name && strcmp(run_name, name)) {
skip = 1;
@ -1368,15 +1372,15 @@ int define_commands(char *run_name)
*/
if (is_desc_line(line_argv[0]) && !skip) {
char *desc = strdup(line_orig);
char *desc = dm_strdup(line_orig);
if (cmd->desc) {
int newlen = strlen(cmd->desc) + strlen(desc) + 2;
char *newdesc = malloc(newlen);
char *newdesc = dm_malloc(newlen);
if (newdesc) {
memset(newdesc, 0, newlen);
snprintf(newdesc, newlen, "%s %s", cmd->desc, desc);
cmd->desc = newdesc;
free(desc);
dm_free(desc);
}
} else
cmd->desc = desc;
@ -1394,7 +1398,7 @@ int define_commands(char *run_name)
}
if (is_id_line(line_argv[0])) {
cmd->command_id = strdup(line_argv[1]);
cmd->command_id = dm_strdup(line_argv[1]);
continue;
}
@ -1757,7 +1761,7 @@ static void print_val_man(const char *str)
if (strstr(str, "|")) {
int len = strlen(str);
line = strdup(str);
line = dm_strdup(str);
split_line(line, &line_argc, line_argv, '|');
for (i = 0; i < line_argc; i++) {
if (i) {