Skip to contentSkip to conversation

libxl: only free vcpu info list when it is allocated

PATCH In review Wei Liu 2 participants 3 messages Oct 21, 2016 – Oct 24, 2016

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 libxl: only free vcpu info list when it is allocated

Clang complains nr_dom_vcpus may be used uninitialized after 4a6070ea9.

The real issue is vinfo can be NULL and nr_dom_vcpus remains uninitialized if previous call fails.

Instead of initializing nr_dom_vcpus to 0, check if vinfo is NULL before calling the free function, because that function can't handle NULL. That should also placate Clang.

---
Cc: Ian Jackson <[email protected]>
Cc: Dario Faggioli <[email protected]>
Cc: Juergen Gross <[email protected]>

---
 tools/libxl/libxl_numa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxl/libxl_numa.c +2 -1
index fd64c22..0bdac2a 100644
@@ -254,7 +254,8 @@ static int nr_vcpus_on_nodes(libxl__gc *gc, libxl_cputopology *tinfo,
 
  next:
         libxl_cpupoolinfo_dispose(&cpupool_info);
-        libxl_vcpuinfo_list_free(vinfo, nr_dom_vcpus);
+        if (vinfo)
+            libxl_vcpuinfo_list_free(vinfo, nr_dom_vcpus);
     }
 
     libxl_bitmap_dispose(&dom_nodemap);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Wei Liu

Clang complains nr_dom_vcpus may be used uninitialized after 4a6070ea9.

The real issue is vinfo can be NULL and nr_dom_vcpus remains uninitialized if previous call fails.

If it were me doing this, I'd just have initialized nr_dom_vcpus to 0.

This is what I've always done when using libxl_numainfo_list_free(), which is similar to this (then how did I miss doing it here? Oh, well... :-/)

And since we're initializing vinfo to NULL already, initializing nr_dom_vcpus as well makes things look more uniform.

That being said, this amounts to personal taste, you're the maintainer, and it's not that I can't stand this solution, so:

Quoted 2 lines

Thanks and 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]
https://lists.xen.org/xen-devel

author
#2 lore raw
Quoted 7 lines · Dario Faggioli
Quoted 6 lines · Wei Liu

Clang complains nr_dom_vcpus may be used uninitialized after 4a6070ea9.

The real issue is vinfo can be NULL and nr_dom_vcpus remains uninitialized if previous call fails.

Quoted 9 lines

If it were me doing this, I'd just have initialized nr_dom_vcpus to 0.

This is what I've always done when using libxl_numainfo_list_free(), which is similar to this (then how did I miss doing it here? Oh, well... :-/)

And since we're initializing vinfo to NULL already, initializing nr_dom_vcpus as well makes things look more uniform.

Right. I think this is a better idea.

I will send out another version of this patch.

Wei.

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