All of lore.kernel.org
 help / color / mirror / Atom feed
From: zhanghailiang <zhang.zhanghailiang@huawei.com>
To: Scott Feldman <sfeldma@gmail.com>
Cc: qemu-trivial@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Jiří Pírko" <jiri@resnulli.us>,
	peter.huangpeng@huawei.com
Subject: Re: [Qemu-trivial] [PATCH] rocker: Fix memory leak reported by coverity
Date: Tue, 23 Jun 2015 13:46:08 +0800	[thread overview]
Message-ID: <5588F2A0.8040001@huawei.com> (raw)
In-Reply-To: <CAE4R7bCCSh6dd_t42rzSiYs_+nEc8FreT2ij1F0iRGem+TjWow@mail.gmail.com>

On 2015/6/23 13:23, Scott Feldman wrote:
> On Mon, Jun 22, 2015 at 6:31 PM, zhanghailiang
> <zhang.zhanghailiang@huawei.com> wrote:
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> ---
>>   hw/net/rocker/rocker.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
>> index 4d25842..d06116e 100644
>> --- a/hw/net/rocker/rocker.c
>> +++ b/hw/net/rocker/rocker.c
>> @@ -103,6 +103,7 @@ RockerSwitch *qmp_query_rocker(const char *name, Error **errp)
>>       if (!r) {
>>           error_set(errp, ERROR_CLASS_GENERIC_ERROR,
>>                     "rocker %s not found", name);
>> +        g_free(rocker);
>>           return NULL;
>>       }
>
> I'll post a patch to fix this one this way, to report alloc failure:
>

Yes, this is another way to fix this problem~

> --- a/hw/net/rocker/rocker.c
> +++ b/hw/net/rocker/rocker.c
> @@ -96,7 +96,7 @@ World *rocker_get_world(Rocker *r, enum
> rocker_world_type type)
>
>   RockerSwitch *qmp_query_rocker(const char *name, Error **errp)
>   {
> -    RockerSwitch *rocker = g_malloc0(sizeof(*rocker));
> +    RockerSwitch *rocker;
>       Rocker *r;
>
>       r = rocker_find(name);
> @@ -106,6 +106,12 @@ RockerSwitch *qmp_query_rocker(const char *name,
> Error **errp)
>           return NULL;
>       }
>
> +    rocker = g_malloc0(sizeof(*rocker));

It's unnecessary to check the return value of 'g_malloc0', because it only
return NULL when the size is 0, obviously, here it is not zero.(sizeof(*rocker)).

> +    if (!rocker) {
> +        error_set(errp, ERROR_CLASS_GENERIC_ERROR, "out-of-memory");
> +        return NULL;
> +    }
> +
>
>




  reply	other threads:[~2015-06-23  5:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-23  1:31 [Qemu-trivial] [PATCH] rocker: Fix memory leak reported by coverity zhanghailiang
2015-06-23  5:23 ` Scott Feldman
2015-06-23  5:46   ` zhanghailiang [this message]
2015-06-23  6:06     ` Scott Feldman
2015-06-23  8:01   ` Paolo Bonzini
2015-06-23  6:06 ` Scott Feldman
2015-07-07  1:20   ` zhanghailiang
2015-07-07  1:33     ` Scott Feldman
2015-07-07  1:48       ` zhanghailiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5588F2A0.8040001@huawei.com \
    --to=zhang.zhanghailiang@huawei.com \
    --cc=jiri@resnulli.us \
    --cc=pbonzini@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-trivial@nongnu.org \
    --cc=sfeldma@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.