fix memory leaks
This commit is contained in:
27
cmd/option.c
27
cmd/option.c
@@ -16,6 +16,33 @@ struct b_command_option *b_command_option_create(void)
|
||||
return out;
|
||||
}
|
||||
|
||||
void b_command_option_destroy(struct b_command_option *opt)
|
||||
{
|
||||
if (opt->opt_long_name) {
|
||||
free(opt->opt_long_name);
|
||||
}
|
||||
|
||||
if (opt->opt_description) {
|
||||
free(opt->opt_description);
|
||||
}
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
|
||||
b_queue_iterator_begin(&opt->opt_args, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct b_command_arg *arg
|
||||
= b_unbox(struct b_command_arg, it.entry, arg_entry);
|
||||
if (!arg) {
|
||||
break;
|
||||
}
|
||||
|
||||
b_queue_iterator_erase(&it);
|
||||
b_command_arg_destroy(arg);
|
||||
}
|
||||
|
||||
free(opt);
|
||||
}
|
||||
|
||||
b_status b_command_option_set_long_name(
|
||||
struct b_command_option *opt, const char *name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user