sched/rt: Fix memory leak in rt_init()
PATCH 1/1 sched/rt: Fix memory leak in rt_init()
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.
---
CC: Wei Liu <[email protected]>
CC: George Dunlap <[email protected]>
CC: Dario Faggioli <[email protected]>
CC: Meng Xu <[email protected]>
--- xen/common/sched_rt.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
xen/common/sched_rt.c +12 -3
@@ -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
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 7 lines · Andrew Cooper
c/s
2656bc7b0"xen: adopt .deinit_pdata and improve timer handling" introduced a error path intort_init()which leaked prv if the allocation ofprv->repl_timerfailed.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?
Quoted 3 lines
Signed-off-by Andrew Cooper <[email protected]>---
I'm sorry that I should have spot it out when I reviewed the code. :-(
-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 11 lines · Meng Xu
Quoted 7 lines · Andrew Cooper
c/s
2656bc7b0"xen: adopt .deinit_pdata and improve timer handling" introduced a error path intort_init()which leaked prv if the allocation ofprv->repl_timerfailed.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.
Quoted 4 lines
Quoted 3 lines
Signed-off-by Andrew Cooper <[email protected]>---
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 ;)
Quoted 2 lines
Reviewed-by Meng Xu <[email protected]>
Thanks,
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 9 lines · Andrew Cooper
c/s
2656bc7b0"xen: adopt .deinit_pdata and improve timer handling" introduced a error path intort_init()which leaked prv if the allocation ofprv->repl_timerfailed.Introduce an error cleanup path.
Spotted by Coverity.
Signed-off-by Andrew Cooper <[email protected]>
But please wait until we cut RC2 to apply this patch
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 5 lines · Wei Liu
Quoted 4 lines · Andrew Cooper
c/s
2656bc7b0"xen: adopt .deinit_pdata and improve timer handling" introduced a error path intort_init()which leaked prv if the allocation ofprv->repl_timerfailed.
Quoted 8 lines
Quoted 5 lines
Introduce an error cleanup path.
Spotted by Coverity.
Signed-off-by Andrew Cooper <[email protected]>Release-acked-by Wei Liu <[email protected]>But please wait until we cut RC2 to apply this patch
Of course. Queued.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel