[Spice-devel,spice-server,16/18] sound: Free more on SndChannel finalize

Submitted by Frediano Ziglio on Nov. 23, 2016, 6:07 p.m.

Details

Message ID 1479924452-15913-17-git-send-email-fziglio@redhat.com
State Superseded
Headers show
Series "Remove DummyChannel* objects" ( rev: 3 2 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Nov. 23, 2016, 6:07 p.m.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 server/sound.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/sound.c b/server/sound.c
index cff34a4..9c9804d 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1420,9 +1420,26 @@  snd_channel_init(SndChannel *self)
 }
 
 static void
+snd_channel_finalize(GObject *object)
+{
+    SndChannel *channel = SND_CHANNEL(object);
+
+    remove_channel(channel);
+
+    free(channel->volume.volume);
+    channel->volume.volume = NULL;
+
+    G_OBJECT_CLASS(snd_channel_parent_class)->finalize(object);
+}
+
+static void
 snd_channel_class_init(SndChannelClass *klass)
 {
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
     RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
+
+    object_class->finalize = snd_channel_finalize;
+
     channel_class->config_socket = snd_channel_config_socket;
     channel_class->alloc_recv_buf = snd_channel_client_alloc_recv_buf;
     channel_class->release_recv_buf = snd_channel_client_release_recv_buf;
@@ -1538,10 +1555,7 @@  static void snd_detach_common(SndChannel *channel)
     }
     RedsState *reds = red_channel_get_server(RED_CHANNEL(channel));
 
-    remove_channel(channel);
     reds_unregister_channel(reds, RED_CHANNEL(channel));
-    free(channel->volume.volume);
-    channel->volume.volume = NULL;
     red_channel_destroy(RED_CHANNEL(channel));
 }
 

Comments

On 11/23/2016 08:07 PM, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  server/sound.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/server/sound.c b/server/sound.c
> index cff34a4..9c9804d 100644
> --- a/server/sound.c
> +++ b/server/sound.c
> @@ -1420,9 +1420,26 @@ snd_channel_init(SndChannel *self)
>  }
>
>  static void
> +snd_channel_finalize(GObject *object)
> +{
> +    SndChannel *channel = SND_CHANNEL(object);
> +
> +    remove_channel(channel);
> +
> +    free(channel->volume.volume);
> +    channel->volume.volume = NULL;
> +
> +    G_OBJECT_CLASS(snd_channel_parent_class)->finalize(object);
> +}
> +
> +static void
>  snd_channel_class_init(SndChannelClass *klass)
>  {
> +    GObjectClass *object_class = G_OBJECT_CLASS(klass);
>      RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
> +
> +    object_class->finalize = snd_channel_finalize;
> +
>      channel_class->config_socket = snd_channel_config_socket;
>      channel_class->alloc_recv_buf = snd_channel_client_alloc_recv_buf;
>      channel_class->release_recv_buf = snd_channel_client_release_recv_buf;
> @@ -1538,10 +1555,7 @@ static void snd_detach_common(SndChannel *channel)
>      }
>      RedsState *reds = red_channel_get_server(RED_CHANNEL(channel));
>
> -    remove_channel(channel);
>      reds_unregister_channel(reds, RED_CHANNEL(channel));
> -    free(channel->volume.volume);
> -    channel->volume.volume = NULL;
>      red_channel_destroy(RED_CHANNEL(channel));
>  }
>
>

Hi Frediano,

Memory that was allocated in _attach better be
freed in _detach.

Regards,
     Uri.
> 
> On 11/23/2016 08:07 PM, Frediano Ziglio wrote:
> > Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> > ---
> >  server/sound.c | 20 +++++++++++++++++---
> >  1 file changed, 17 insertions(+), 3 deletions(-)
> >
> > diff --git a/server/sound.c b/server/sound.c
> > index cff34a4..9c9804d 100644
> > --- a/server/sound.c
> > +++ b/server/sound.c
> > @@ -1420,9 +1420,26 @@ snd_channel_init(SndChannel *self)
> >  }
> >
> >  static void
> > +snd_channel_finalize(GObject *object)
> > +{
> > +    SndChannel *channel = SND_CHANNEL(object);
> > +
> > +    remove_channel(channel);
> > +
> > +    free(channel->volume.volume);
> > +    channel->volume.volume = NULL;
> > +
> > +    G_OBJECT_CLASS(snd_channel_parent_class)->finalize(object);
> > +}
> > +
> > +static void
> >  snd_channel_class_init(SndChannelClass *klass)
> >  {
> > +    GObjectClass *object_class = G_OBJECT_CLASS(klass);
> >      RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
> > +
> > +    object_class->finalize = snd_channel_finalize;
> > +
> >      channel_class->config_socket = snd_channel_config_socket;
> >      channel_class->alloc_recv_buf = snd_channel_client_alloc_recv_buf;
> >      channel_class->release_recv_buf = snd_channel_client_release_recv_buf;
> > @@ -1538,10 +1555,7 @@ static void snd_detach_common(SndChannel *channel)
> >      }
> >      RedsState *reds = red_channel_get_server(RED_CHANNEL(channel));
> >
> > -    remove_channel(channel);
> >      reds_unregister_channel(reds, RED_CHANNEL(channel));
> > -    free(channel->volume.volume);
> > -    channel->volume.volume = NULL;
> >      red_channel_destroy(RED_CHANNEL(channel));
> >  }
> >
> >
> 
> Hi Frediano,
> 
> Memory that was allocated in _attach better be
> freed in _detach.
> 
> Regards,
>      Uri.
> 
> 

Sorry, I don't understand.
Now the attach functions just create objects so the object is
responsible to free its stuff.

Frediano