qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Add missing initialization for g_autofree variables
@ 2021-03-15  8:00 mrezanin
  2021-03-15  8:08 ` Thomas Huth
  0 siblings, 1 reply; 3+ messages in thread
From: mrezanin @ 2021-03-15  8:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Huth, Cornelia Huck

From: Miroslav Rezanina <mrezanin@redhat.com>

When declaring g_autofree variable without inicialization, compiler
will raise "may be used uninitialized in this function" warning due
to automatic free handling.

This is mentioned in docs/devel/style.rst (quote from section
"Automatic memory deallocation"):

  * Variables declared with g_auto* MUST always be initialized,
    otherwise the cleanup function will use uninitialized stack memory

Add inicialization to NULL for these declaration to prevent this
warning.

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>

---
* From v1:
  -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c
     fixed by patch sent by Zenghui Yu (multi-process: Initialize
     variables declared with g_auto*)
---
 hw/s390x/s390-pci-vfio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index ead4f222d5..0ee7dc21f2 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -29,7 +29,7 @@
  */
 bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
 {
-    g_autofree struct vfio_iommu_type1_info *info;
+    g_autofree struct vfio_iommu_type1_info *info = NULL;
     uint32_t argsz;
 
     assert(avail);
@@ -230,7 +230,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
  */
 void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
 {
-    g_autofree struct vfio_device_info *info;
+    g_autofree struct vfio_device_info *info = NULL;
     VFIOPCIDevice *vfio_pci;
     uint32_t argsz;
     int fd;
-- 
2.27.0



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

end of thread, other threads:[~2021-03-15  8:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-15  8:00 [PATCH v2] Add missing initialization for g_autofree variables mrezanin
2021-03-15  8:08 ` Thomas Huth
2021-03-15  8:35   ` Miroslav Rezanina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).