All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.7] sched/rt: Fix memory leak in rt_init()
@ 2016-05-10 13:38 Andrew Cooper
  2016-05-10 13:52 ` Meng Xu
  2016-05-10 14:18 ` Wei Liu
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Cooper @ 2016-05-10 13:38 UTC (permalink / raw)
  To: Xen-devel; +Cc: George Dunlap, Andrew Cooper, Dario Faggioli, Wei Liu, Meng Xu

c/s 2656bc7b0 "xen: adopt .deinit_pdata and improve timer handling"
introduced a error path into rt_init() which leaked prv if the
allocation of prv->repl_timer failed.

Introduce an error cleanup path.

Spotted by Coverity.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Wei Liu <wei.liu2@citrix.com>
CC: George Dunlap <george.dunlap@eu.citrix.com>
CC: Dario Faggioli <dario.faggioli@citrix.com>
CC: Meng Xu <mengxu@cis.upenn.edu>
---
 xen/common/sched_rt.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c
index 7f8f411..aa3ffd2 100644
--- a/xen/common/sched_rt.c
+++ b/xen/common/sched_rt.c
@@ -581,6 +581,7 @@ replq_reinsert(const struct scheduler *ops, struct rt_vcpu *svc)
 static int
 rt_init(struct scheduler *ops)
 {
+    int rc = -ENOMEM;
     struct rt_private *prv = xzalloc(struct rt_private);
 
     printk("Initializing RTDS scheduler\n"
@@ -588,11 +589,11 @@ rt_init(struct scheduler *ops)
            "Use at your own risk.\n");
 
     if ( prv == NULL )
-        return -ENOMEM;
+        goto err;
 
     prv->repl_timer = xzalloc(struct timer);
     if ( prv->repl_timer == NULL )
-        return -ENOMEM;
+        goto err;
 
     spin_lock_init(&prv->lock);
     INIT_LIST_HEAD(&prv->sdom);
@@ -603,8 +604,16 @@ rt_init(struct scheduler *ops)
     cpumask_clear(&prv->tickled);
 
     ops->sched_data = prv;
+    rc = 0;
 
-    return 0;
+ err:
+    if ( rc && prv )
+    {
+        xfree(prv->repl_timer);
+        xfree(prv);
+    }
+
+    return rc;
 }
 
 static void
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH for-4.7] sched/rt: Fix memory leak in rt_init()
  2016-05-10 13:38 [PATCH for-4.7] sched/rt: Fix memory leak in rt_init() Andrew Cooper
@ 2016-05-10 13:52 ` Meng Xu
  2016-05-10 13:57   ` Andrew Cooper
  2016-05-10 14:18 ` Wei Liu
  1 sibling, 1 reply; 5+ messages in thread
From: Meng Xu @ 2016-05-10 13:52 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: George Dunlap, Dario Faggioli, Wei Liu, Xen-devel

On Tue, May 10, 2016 at 9:38 AM, Andrew Cooper
<andrew.cooper3@citrix.com> wrote:
> c/s 2656bc7b0 "xen: adopt .deinit_pdata and improve timer handling"
> introduced a error path into rt_init() which leaked prv if the
> allocation of prv->repl_timer failed.
>
> Introduce an error cleanup path.
>
> Spotted by Coverity.

I'm curious about this line. Does it mean that this is spotted by the
coverty code review or by some automatical testing/checking?

>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---

I'm sorry that I should have spot it out when I reviewed the code. :-(

Reviewed-by: Meng Xu <mengxu@cis.upenn.edu>


-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH for-4.7] sched/rt: Fix memory leak in rt_init()
  2016-05-10 13:52 ` Meng Xu
@ 2016-05-10 13:57   ` Andrew Cooper
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Cooper @ 2016-05-10 13:57 UTC (permalink / raw)
  To: Meng Xu; +Cc: George Dunlap, Dario Faggioli, Wei Liu, Xen-devel

On 10/05/16 14:52, Meng Xu wrote:
> On Tue, May 10, 2016 at 9:38 AM, Andrew Cooper
> <andrew.cooper3@citrix.com> wrote:
>> c/s 2656bc7b0 "xen: adopt .deinit_pdata and improve timer handling"
>> introduced a error path into rt_init() which leaked prv if the
>> allocation of prv->repl_timer failed.
>>
>> Introduce an error cleanup path.
>>
>> Spotted by Coverity.
> I'm curious about this line. Does it mean that this is spotted by the
> coverty code review or by some automatical testing/checking?

XenServer has our Coverity instance hooked up to every build.

Every time I pull a new version of staging, I get a Coverity report as a
delta from the last build.

>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> ---
> I'm sorry that I should have spot it out when I reviewed the code. :-(

No worries - if this was easy to start with, tools like Coverity
wouldn't exist ;)

>
> Reviewed-by: Meng Xu <mengxu@cis.upenn.edu>

Thanks,

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH for-4.7] sched/rt: Fix memory leak in rt_init()
  2016-05-10 13:38 [PATCH for-4.7] sched/rt: Fix memory leak in rt_init() Andrew Cooper
  2016-05-10 13:52 ` Meng Xu
@ 2016-05-10 14:18 ` Wei Liu
  2016-05-10 14:18   ` Andrew Cooper
  1 sibling, 1 reply; 5+ messages in thread
From: Wei Liu @ 2016-05-10 14:18 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: George Dunlap, Dario Faggioli, Wei Liu, Meng Xu, Xen-devel

On Tue, May 10, 2016 at 02:38:48PM +0100, Andrew Cooper wrote:
> c/s 2656bc7b0 "xen: adopt .deinit_pdata and improve timer handling"
> introduced a error path into rt_init() which leaked prv if the
> allocation of prv->repl_timer failed.
> 
> Introduce an error cleanup path.
> 
> Spotted by Coverity.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Release-acked-by: Wei Liu <wei.liu2@citrix.com>

But please wait until we cut RC2 to apply this patch

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH for-4.7] sched/rt: Fix memory leak in rt_init()
  2016-05-10 14:18 ` Wei Liu
@ 2016-05-10 14:18   ` Andrew Cooper
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Cooper @ 2016-05-10 14:18 UTC (permalink / raw)
  To: Wei Liu; +Cc: George Dunlap, Dario Faggioli, Meng Xu, Xen-devel

On 10/05/16 15:18, Wei Liu wrote:
> On Tue, May 10, 2016 at 02:38:48PM +0100, Andrew Cooper wrote:
>> c/s 2656bc7b0 "xen: adopt .deinit_pdata and improve timer handling"
>> introduced a error path into rt_init() which leaked prv if the
>> allocation of prv->repl_timer failed.
>>
>> Introduce an error cleanup path.
>>
>> Spotted by Coverity.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Release-acked-by: Wei Liu <wei.liu2@citrix.com>
>
> But please wait until we cut RC2 to apply this patch

Of course.  Queued.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

end of thread, other threads:[~2016-05-10 14:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-10 13:38 [PATCH for-4.7] sched/rt: Fix memory leak in rt_init() Andrew Cooper
2016-05-10 13:52 ` Meng Xu
2016-05-10 13:57   ` Andrew Cooper
2016-05-10 14:18 ` Wei Liu
2016-05-10 14:18   ` Andrew Cooper

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.