mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
Fix some small memory leaks
Found with -fsanitize=leak Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
967c870498
commit
8ba5e814fd
@ -108,6 +108,7 @@ int cmd_setattr(int argc, char *argv[])
|
|||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++)
|
||||||
do_setattr(argv[i], opts);
|
do_setattr(argv[i], opts);
|
||||||
|
bch2_opt_strs_free(&opts);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,7 @@ int cmd_format(int argc, char *argv[])
|
|||||||
fs_opts,
|
fs_opts,
|
||||||
opts,
|
opts,
|
||||||
devices.item, darray_size(devices));
|
devices.item, darray_size(devices));
|
||||||
|
bch2_opt_strs_free(&fs_opt_strs);
|
||||||
|
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
bch2_sb_print(sb, false, 1 << BCH_SB_FIELD_members, HUMAN_READABLE);
|
bch2_sb_print(sb, false, 1 << BCH_SB_FIELD_members, HUMAN_READABLE);
|
||||||
|
@ -773,10 +773,12 @@ int cmd_migrate(int argc, char *argv[])
|
|||||||
if (format_opts.encrypted && !no_passphrase)
|
if (format_opts.encrypted && !no_passphrase)
|
||||||
format_opts.passphrase = read_passphrase_twice("Enter passphrase: ");
|
format_opts.passphrase = read_passphrase_twice("Enter passphrase: ");
|
||||||
|
|
||||||
return migrate_fs(fs_path,
|
int ret = migrate_fs(fs_path,
|
||||||
fs_opt_strs,
|
fs_opt_strs,
|
||||||
fs_opts,
|
fs_opts,
|
||||||
format_opts, force);
|
format_opts, force);
|
||||||
|
bch2_opt_strs_free(&fs_opt_strs);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void migrate_superblock_usage(void)
|
static void migrate_superblock_usage(void)
|
||||||
|
@ -1006,6 +1006,16 @@ int bchu_data(struct bchfs_handle fs, struct bch_ioctl_data cmd)
|
|||||||
|
|
||||||
/* option parsing */
|
/* option parsing */
|
||||||
|
|
||||||
|
void bch2_opt_strs_free(struct bch_opt_strs *opts)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < bch2_opts_nr; i++) {
|
||||||
|
free(opts->by_id[i]);
|
||||||
|
opts->by_id[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct bch_opt_strs bch2_cmdline_opts_get(int *argc, char *argv[],
|
struct bch_opt_strs bch2_cmdline_opts_get(int *argc, char *argv[],
|
||||||
unsigned opt_types)
|
unsigned opt_types)
|
||||||
{
|
{
|
||||||
@ -1038,9 +1048,8 @@ struct bch_opt_strs bch2_cmdline_opts_get(int *argc, char *argv[],
|
|||||||
optid = bch2_opt_lookup(optstr);
|
optid = bch2_opt_lookup(optstr);
|
||||||
if (optid < 0 ||
|
if (optid < 0 ||
|
||||||
!(bch2_opt_table[optid].mode & opt_types)) {
|
!(bch2_opt_table[optid].mode & opt_types)) {
|
||||||
free(optstr);
|
|
||||||
i++;
|
i++;
|
||||||
continue;
|
goto next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valstr &&
|
if (!valstr &&
|
||||||
@ -1052,13 +1061,15 @@ struct bch_opt_strs bch2_cmdline_opts_get(int *argc, char *argv[],
|
|||||||
if (!valstr)
|
if (!valstr)
|
||||||
valstr = "1";
|
valstr = "1";
|
||||||
|
|
||||||
opts.by_id[optid] = valstr;
|
opts.by_id[optid] = strdup(valstr);
|
||||||
|
|
||||||
*argc -= nr_args;
|
*argc -= nr_args;
|
||||||
memmove(&argv[i],
|
memmove(&argv[i],
|
||||||
&argv[i + nr_args],
|
&argv[i + nr_args],
|
||||||
sizeof(char *) * (*argc - i));
|
sizeof(char *) * (*argc - i));
|
||||||
argv[*argc] = NULL;
|
argv[*argc] = NULL;
|
||||||
|
next:
|
||||||
|
free(optstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
|
@ -25,6 +25,7 @@ struct {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void bch2_opt_strs_free(struct bch_opt_strs *);
|
||||||
struct bch_opt_strs bch2_cmdline_opts_get(int *, char *[], unsigned);
|
struct bch_opt_strs bch2_cmdline_opts_get(int *, char *[], unsigned);
|
||||||
struct bch_opts bch2_parse_opts(struct bch_opt_strs);
|
struct bch_opts bch2_parse_opts(struct bch_opt_strs);
|
||||||
void bch2_opts_usage(unsigned);
|
void bch2_opts_usage(unsigned);
|
||||||
|
@ -1138,6 +1138,8 @@ static int check_directory_structure(struct bch_fs *c,
|
|||||||
|
|
||||||
BUG_ON(ret == -EINTR);
|
BUG_ON(ret == -EINTR);
|
||||||
|
|
||||||
|
kfree(path.entries);
|
||||||
|
|
||||||
return bch2_trans_exit(&trans) ?: ret;
|
return bch2_trans_exit(&trans) ?: ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user