On Thu, 12 Mar 2026 at 12:17, Trieu Huynh <[email protected]> wrote:
>
> migrate_add_blocker() can fail (e.g. if migration is already in
> progress), in which case it returns a negative value and populates
> its errp argument with the reason.
>
> The previous code ignored the return value, leaving state
> inconsistent on failure. Fix this by:
> - Passing a local Error ** so failure details can be reported.
> - Checking the return value; on failure, report the error, free the
>   migration_blocker Error object, and return NULL to the caller.
>
> Resolves: CID 1645470
>
> Signed-off-by: Trieu Huynh <[email protected]>
> ---
>  plugins/api-system.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/plugins/api-system.c b/plugins/api-system.c
> index 9a70b9caa6..f0d6cefe74 100644
> --- a/plugins/api-system.c
> +++ b/plugins/api-system.c
> @@ -105,10 +105,16 @@ static Error *migration_blocker;
>  const void *qemu_plugin_request_time_control(void)
>  {
>      if (!has_control) {
> +        Error *local_err = NULL;
>          has_control = true;
>          error_setg(&migration_blocker,
>                     "TCG plugin time control does not support migration");
> -        migrate_add_blocker(&migration_blocker, NULL);
> +        if (migrate_add_blocker(&migration_blocker, &local_err) < 0) {
> +            error_report_err(local_err);
> +            error_free(migration_blocker);
> +            migration_blocker = NULL;

You don't need to free the migration_blocker Error if
migrate_add_blocker() fails -- the function documents that it
will do that for you and set the pointer to NULL.

> +            migration_blocker = NULL;
> +            return NULL;
> +        }
>          return &has_control;

thanks
-- PMM

Reply via email to