qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ossaudio: fix memory leak
@ 2015-06-23  1:01 arei.gonglei
  2015-06-23  7:35 ` Markus Armbruster
  0 siblings, 1 reply; 3+ messages in thread
From: arei.gonglei @ 2015-06-23  1:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gonglei, kraxel

From: Gonglei <arei.gonglei@huawei.com>

Variable "conf" going out of scope leaks the storage
it points to in line 856.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 audio/ossaudio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 11e76a1..7dbe333 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -853,6 +853,7 @@ static void *oss_audio_init (void)
 
     if (access(conf->devpath_in, R_OK | W_OK) < 0 ||
         access(conf->devpath_out, R_OK | W_OK) < 0) {
+        g_free(conf);
         return NULL;
     }
     return conf;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] ossaudio: fix memory leak
  2015-06-23  1:01 [Qemu-devel] [PATCH] ossaudio: fix memory leak arei.gonglei
@ 2015-06-23  7:35 ` Markus Armbruster
  2015-06-23  8:03   ` Gonglei
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Armbruster @ 2015-06-23  7:35 UTC (permalink / raw)
  To: arei.gonglei; +Cc: qemu-trivial, qemu-devel, kraxel

<arei.gonglei@huawei.com> writes:

> From: Gonglei <arei.gonglei@huawei.com>
>
> Variable "conf" going out of scope leaks the storage
> it points to in line 856.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  audio/ossaudio.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
> index 11e76a1..7dbe333 100644
> --- a/audio/ossaudio.c
> +++ b/audio/ossaudio.c
> @@ -853,6 +853,7 @@ static void *oss_audio_init (void)
   static void *oss_audio_init (void)
   {
       OSSConf *conf = g_malloc(sizeof(OSSConf));
       *conf = glob_conf;
>  
>      if (access(conf->devpath_in, R_OK | W_OK) < 0 ||
>          access(conf->devpath_out, R_OK | W_OK) < 0) {
> +        g_free(conf);
>          return NULL;
>      }
>      return conf;
   }

Simpler (untested):

   static void *oss_audio_init (void)
   {
       if (access(globconf.devpath_in, R_OK | W_OK) < 0 ||
           access(globconf.devpath_out, R_OK | W_OK) < 0) {
           return NULL;
       }
       return g_memdup(&glob_conf, sizeof(glob_conf));
   }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] ossaudio: fix memory leak
  2015-06-23  7:35 ` Markus Armbruster
@ 2015-06-23  8:03   ` Gonglei
  0 siblings, 0 replies; 3+ messages in thread
From: Gonglei @ 2015-06-23  8:03 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-trivial, qemu-devel, kraxel

On 2015/6/23 15:35, Markus Armbruster wrote:
> <arei.gonglei@huawei.com> writes:
> 
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> Variable "conf" going out of scope leaks the storage
>> it points to in line 856.
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> ---
>>  audio/ossaudio.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
>> index 11e76a1..7dbe333 100644
>> --- a/audio/ossaudio.c
>> +++ b/audio/ossaudio.c
>> @@ -853,6 +853,7 @@ static void *oss_audio_init (void)
>    static void *oss_audio_init (void)
>    {
>        OSSConf *conf = g_malloc(sizeof(OSSConf));
>        *conf = glob_conf;
>>  
>>      if (access(conf->devpath_in, R_OK | W_OK) < 0 ||
>>          access(conf->devpath_out, R_OK | W_OK) < 0) {
>> +        g_free(conf);
>>          return NULL;
>>      }
>>      return conf;
>    }
> 
> Simpler (untested):
> 
>    static void *oss_audio_init (void)
>    {
>        if (access(globconf.devpath_in, R_OK | W_OK) < 0 ||
>            access(globconf.devpath_out, R_OK | W_OK) < 0) {
>            return NULL;
>        }
>        return g_memdup(&glob_conf, sizeof(glob_conf));
>    }
> 
I think your approach is better :)
Do you want to submit a patch? Or let me post v2 for this?

Regards,
-Gonglei

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-23  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-23  1:01 [Qemu-devel] [PATCH] ossaudio: fix memory leak arei.gonglei
2015-06-23  7:35 ` Markus Armbruster
2015-06-23  8:03   ` Gonglei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).