Skip to contentSkip to conversation

xen/sched_rc: Fix memory leak in rt_init()

PATCH In review Andrew Cooper 3 participants 3 messages Jun 5, 2015 – Jun 8, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/sched_rc: Fix memory leak in rt_init()

Introduced by c/s 376bbba "sched_rt: print useful affinity info when dumping". If the allocation of cpumask failed, prv was leaked.

Coverity-ID: 1304398
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Dario Faggioli <[email protected]>
CC: George Dunlap <[email protected]>
CC: Meng Xu <[email protected]>

---
 xen/common/sched_rt.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/sched_rt.c +5 -1
index 5836d27..4372486 100644
@@ -441,7 +441,7 @@ static inline struct list_head *rt_depletedq(const struct scheduler *ops)
     {
         _cpumask_scratch = xmalloc_array(cpumask_var_t, nr_cpu_ids);
         if ( !_cpumask_scratch )
-            return -ENOMEM;
+            goto no_mem;
     }
     nr_rt_ops++;
 
@@ -455,6 +455,10 @@ static inline struct list_head *rt_depletedq(const struct scheduler *ops)
     ops->sched_data = prv;
 
     return 0;
+
+ no_mem:
+    xfree(prv);
+    return -ENOMEM;
 }
 
 static void
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Andrew Cooper

Introduced by c/s 376bbba "sched_rt: print useful affinity info when dumping". If the allocation of cpumask failed, prv was leaked.

Wow... I really did a _great_ job with that patch, didn't I? :-//

Quoted 8 lines

Coverity-ID: 1304398
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Dario Faggioli <[email protected]>
CC: George Dunlap <[email protected]>
CC: Meng Xu <[email protected]>

Although, I'd rather...

xen/common/sched_rt.c static inline struct list_head *rt_depletedq(const struct scheduler *ops) · line 445

Quoted 11 lines
xen/common/sched_rt.c +1 -1
index 5836d27..4372486 100644
@@ -441,7 +441,7 @@ static inline struct list_head *rt_depletedq(const struct scheduler *ops)
     {
         _cpumask_scratch = xmalloc_array(cpumask_var_t, nr_cpu_ids);
         if ( !_cpumask_scratch )
-            return -ENOMEM;
+            goto no_mem;
 

free it right away here (just one added line), instead of "clobbering" the tail of the function, since it's just this.

But, really, I'm ok with the fix as is. Thanks for taking the time of sending the patch! :-)

Regards, Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel