player/command: fix mem leak in user-data property; closes #11436

This commit is contained in:
rcombs 2023-03-10 18:07:00 -05:00
parent 3a2f8d42ab
commit 3eb2dfe2eb
1 changed files with 5 additions and 0 deletions

View File

@ -3578,6 +3578,7 @@ struct udata_ctx {
MPContext *mpctx; MPContext *mpctx;
const char *path; const char *path;
mpv_node *node; mpv_node *node;
void *ta_parent;
}; };
static int do_op_udata(struct udata_ctx* ctx, int action, void *arg) static int do_op_udata(struct udata_ctx* ctx, int action, void *arg)
@ -3603,6 +3604,7 @@ static int do_op_udata(struct udata_ctx* ctx, int action, void *arg)
case M_PROPERTY_SET_NODE: case M_PROPERTY_SET_NODE:
assert(node); assert(node);
m_option_copy(&udata_type, node, arg); m_option_copy(&udata_type, node, arg);
talloc_steal(ctx->ta_parent, node_get_alloc(node));
mp_notify_property(mpctx, ctx->path); mp_notify_property(mpctx, ctx->path);
return M_PROPERTY_OK; return M_PROPERTY_OK;
case M_PROPERTY_KEY_ACTION: { case M_PROPERTY_KEY_ACTION: {
@ -3678,6 +3680,7 @@ static int do_op_udata(struct udata_ctx* ctx, int action, void *arg)
struct udata_ctx nctx = *ctx; struct udata_ctx nctx = *ctx;
nctx.node = cnode; nctx.node = cnode;
nctx.ta_parent = node_get_alloc(node);
// If we're going down another level, set up a new key-action. // If we're going down another level, set up a new key-action.
if (has_split) { if (has_split) {
@ -3700,6 +3703,7 @@ static int do_list_udata(int item, int action, void *arg, void *ctx)
{ {
struct udata_ctx nctx = *(struct udata_ctx*)ctx; struct udata_ctx nctx = *(struct udata_ctx*)ctx;
nctx.node = &nctx.node->u.list->values[item]; nctx.node = &nctx.node->u.list->values[item];
nctx.ta_parent = &nctx.node->u.list;
return do_op_udata(&nctx, action, arg); return do_op_udata(&nctx, action, arg);
} }
@ -3725,6 +3729,7 @@ static int mp_property_udata(void *ctx, struct m_property *prop,
.mpctx = mpctx, .mpctx = mpctx,
.path = path, .path = path,
.node = &mpctx->command_ctx->udata, .node = &mpctx->command_ctx->udata,
.ta_parent = &mpctx->command_ctx,
}; };
int ret = do_op_udata(&nctx, action, arg); int ret = do_op_udata(&nctx, action, arg);