Skip to content

Commit a6c8195

Browse files
committed
player/command: fix def-val logic and choices leak
Use m_option_get_node to get default value. Fix choices talloc_strdup memory leak.
1 parent e346915 commit a6c8195

1 file changed

Lines changed: 7 additions & 22 deletions

File tree

player/command.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,27 +4010,6 @@ static int mp_property_commands(void *ctx, struct m_property *prop,
40104010
node_map_add_string(ae, "name", a->name);
40114011
node_map_add_string(ae, "type", a->type->name);
40124012
node_map_add_flag(ae, "optional", a->flags & MP_CMD_OPT_ARG);
4013-
if (a->defval) {
4014-
if (a->type == &m_option_type_int) {
4015-
node_map_add_int64(ae, "default-value",
4016-
*(const int *)a->defval);
4017-
} else if (a->type == &m_option_type_int64) {
4018-
node_map_add_int64(ae, "default-value",
4019-
*(const int64_t *)a->defval);
4020-
} else if (a->type == &m_option_type_double) {
4021-
node_map_add_double(ae, "default-value",
4022-
*(const double *)a->defval);
4023-
} else if (a->type == &m_option_type_float) {
4024-
node_map_add_double(ae, "default-value",
4025-
*(const double *)a->defval);
4026-
} else if (a->type == &m_option_type_flag) {
4027-
node_map_add_flag(ae, "default-value",
4028-
*(const bool *)a->defval);
4029-
} else if (a->type == &m_option_type_string) {
4030-
node_map_add_string(ae, "default-value",
4031-
*(const char **)a->defval);
4032-
}
4033-
}
40344013
if (a->type == &m_option_type_choice ||
40354014
a->type == &m_option_type_flags) {
40364015
const struct m_opt_choice_alternatives *alt = a->priv;
@@ -4046,9 +4025,15 @@ static int mp_property_commands(void *ctx, struct m_property *prop,
40464025
for (int j = 0; alt[j].name; j++) {
40474026
struct mpv_node *ce = node_array_add(choices, MPV_FORMAT_NONE);
40484027
ce->format = MPV_FORMAT_STRING;
4049-
ce->u.string = talloc_strdup(NULL, alt[j].name);
4028+
ce->u.string = talloc_strdup(choices->u.list, alt[j].name);
40504029
}
40514030
}
4031+
} else {
4032+
if (a->defval) {
4033+
struct mpv_node *def =
4034+
node_map_add(ae, "default-value", MPV_FORMAT_NONE);
4035+
m_option_get_node(a, NULL, def, (void *)a->defval);
4036+
}
40524037
}
40534038
}
40544039

0 commit comments

Comments
 (0)