[Spice-devel] [spice-gtk] Fix using NULL main channel reference

Frediano Ziglio fziglio at redhat.com
Tue Jul 17 07:20:42 UTC 2018


> 
> The main channel reference d->main of SpiceWidget is initialized on
> construction. However, it is used a couple of times before that moment
> while setting the default values of some properties, like resize-guest.
> This results in some annoying critical log messages. This commit makes
> sure that d->main is not used in such situations if it is NULL.
> ---
>  src/spice-widget.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/spice-widget.c b/src/spice-widget.c
> index 72f5334..5187b0c 100644
> --- a/src/spice-widget.c
> +++ b/src/spice-widget.c
> @@ -255,7 +255,7 @@ static void update_ready(SpiceDisplay *display)
>       * state here. If 'resize-guest' is false, we can assume that the
>       * application will manage the state of the displays.
>       */
> -    if (d->resize_guest_enable) {
> +    if (d->resize_guest_enable && d->main) {
>          spice_main_channel_update_display_enabled(d->main,
>          get_display_id(display), ready, TRUE);
>      }
>  
> @@ -1247,7 +1247,7 @@ static void recalc_geometry(GtkWidget *widget)
>                    d->area.width, d->area.height,
>                    d->ww, d->wh, zoom);
>  
> -    if (d->resize_guest_enable)
> +    if (d->resize_guest_enable && d->main)
>          spice_main_channel_update_display(d->main, get_display_id(display),
>                                            d->area.x, d->area.y, d->ww /
>                                            zoom, d->wh / zoom, TRUE);
>  }

Seems a good idea.
Some people seems to prefer the "d->main != NULL" style, for me is fine
this one.

Not knowing much the lifetimes of the various objects I don't know if
would be sensible to make sure that d->main is initialized as soon as possible.

Frediano


More information about the Spice-devel mailing list