client: don't take ownership of result if it is not returned

This fixes memory leak that occured when NULL was passed as result.
This commit is contained in:
heather7283
2025-08-05 18:09:21 +04:00
committed by Kacper Michajłow
parent 1d71523407
commit 91b79d961a

View File

@@ -1149,7 +1149,7 @@ int mpv_command(mpv_handle *ctx, const char **args)
int mpv_command_node(mpv_handle *ctx, mpv_node *args, mpv_node *result)
{
struct mpv_node rn = {.format = MPV_FORMAT_NONE};
int r = run_client_command(ctx, mp_input_parse_cmd_node(ctx->log, args), &rn);
int r = run_client_command(ctx, mp_input_parse_cmd_node(ctx->log, args), result ? &rn : NULL);
if (result && r >= 0)
*result = rn;
return r;
@@ -1158,7 +1158,7 @@ int mpv_command_node(mpv_handle *ctx, mpv_node *args, mpv_node *result)
int mpv_command_ret(mpv_handle *ctx, const char **args, mpv_node *result)
{
struct mpv_node rn = {.format = MPV_FORMAT_NONE};
int r = run_client_command(ctx, mp_input_parse_cmd_strv(ctx->log, args), &rn);
int r = run_client_command(ctx, mp_input_parse_cmd_strv(ctx->log, args), result ? &rn : NULL);
if (result && r >= 0)
*result = rn;
return r;