Re: [PATCH 8/8] Protect globals servers variable with a mutex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>


On Mon, 2016-06-20 at 10:15 +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
> ---
>  server/reds.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/server/reds.c b/server/reds.c
> index c139d8d..f571379 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -151,6 +151,7 @@ static pthread_mutex_t *lock_cs;
>  /* TODO while we can technically create more than one server in a process,
>   * the intended use is to support a single server per process */
>  static GList *servers = NULL;
> +static pthread_mutex_t global_reds_lock = PTHREAD_MUTEX_INITIALIZER;
>  
>  /* SPICE configuration set through the public spice_server_set_xxx APIS */
>  struct RedServerConfig {
> @@ -2912,10 +2913,12 @@ SPICE_DESTRUCTOR_FUNC(reds_exit)
>  {
>      GList *l;
>  
> +    pthread_mutex_lock(&global_reds_lock);
>      for (l = servers; l != NULL; l = l->next) {
>          RedsState *reds = l->data;
>          reds_cleanup(reds);
>      }
> +    pthread_mutex_unlock(&global_reds_lock);
>  }
>  
>  static inline void on_activating_ticketing(RedsState *reds)
> @@ -3486,7 +3489,9 @@ static int do_spice_init(RedsState *reds,
> SpiceCoreInterface *core_interface)
>      if (reds->allow_multiple_clients) {
>          spice_warning("spice: allowing multiple client connections");
>      }
> +    pthread_mutex_lock(&global_reds_lock);
>      servers = g_list_prepend(servers, reds);
> +    pthread_mutex_unlock(&global_reds_lock);
>      return 0;
>  
>  err:
> @@ -3683,7 +3688,9 @@ SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer
> *reds)
>  
>      /* remove the server from the list of servers so that we don't attempt to
>       * free it again at exit */
> +    pthread_mutex_lock(&global_reds_lock);
>      servers = g_list_remove(servers, reds);
> +    pthread_mutex_unlock(&global_reds_lock);
>  }
>  
>  SPICE_GNUC_VISIBLE spice_compat_version_t
> spice_get_current_compat_version(void)
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]