From: Cornelia Huck <cohuck@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Eric Farman" <farman@linux.ibm.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Alex Williamson" <alex.williamson@redhat.com>,
qemu-devel@nongnu.org, qemu-s390x@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PULL 10/19] vfio-ccw: plug memory leak while getting region info
Date: Fri, 2 Oct 2020 14:11:09 +0200 [thread overview]
Message-ID: <20201002121118.180315-11-cohuck@redhat.com> (raw)
In-Reply-To: <20201002121118.180315-1-cohuck@redhat.com>
vfio_get_dev_region_info() unconditionally allocates memory
for a passed-in vfio_region_info structure (and does not re-use
an already allocated structure). Therefore, we have to free
the structure we pass to that function in vfio_ccw_get_region()
for every region we successfully obtained information for.
Fixes: 8fadea24de4e ("vfio-ccw: support async command subregion")
Fixes: 46ea3841edaf ("vfio-ccw: Add support for the schib region")
Fixes: f030532f2ad6 ("vfio-ccw: Add support for the CRW region and IRQ")
Reported-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200928101701.13540-1-cohuck@redhat.com>
---
hw/vfio/ccw.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index ff7f36977994..d2755d7fc5ca 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -491,6 +491,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
vcdev->io_region_offset = info->offset;
vcdev->io_region = g_malloc0(info->size);
+ g_free(info);
/* check for the optional async command region */
ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
@@ -503,6 +504,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
}
vcdev->async_cmd_region_offset = info->offset;
vcdev->async_cmd_region = g_malloc0(info->size);
+ g_free(info);
}
ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
@@ -515,6 +517,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
}
vcdev->schib_region_offset = info->offset;
vcdev->schib_region = g_malloc(info->size);
+ g_free(info);
}
ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
@@ -528,9 +531,9 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
}
vcdev->crw_region_offset = info->offset;
vcdev->crw_region = g_malloc(info->size);
+ g_free(info);
}
- g_free(info);
return;
out_err:
--
2.25.4
next prev parent reply other threads:[~2020-10-02 12:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 12:10 [PULL 00/19] s390x changes Cornelia Huck
2020-10-02 12:11 ` [PULL 01/19] hw/s390x/css: Remove double initialization Cornelia Huck
2020-10-02 12:11 ` [PULL 02/19] s390/sclp: get machine once during read scp/cpu info Cornelia Huck
2020-10-02 12:11 ` [PULL 03/19] s390/sclp: rework sclp boundary checks Cornelia Huck
2020-10-02 12:11 ` [PULL 04/19] s390/sclp: read sccb from mem based on provided length Cornelia Huck
2020-10-02 12:11 ` [PULL 05/19] s390/sclp: check sccb len before filling in data Cornelia Huck
2020-10-02 12:11 ` [PULL 06/19] s390/sclp: use cpu offset to locate cpu entries Cornelia Huck
2020-10-02 12:11 ` [PULL 07/19] s390/sclp: add extended-length sccb support for kvm guest Cornelia Huck
2020-10-02 12:11 ` [PULL 08/19] s390: guest support for diagnose 0x318 Cornelia Huck
2020-10-02 12:11 ` [PULL 09/19] s390x/tcg: Implement MONITOR CALL Cornelia Huck
2020-10-02 12:11 ` Cornelia Huck [this message]
2020-10-02 12:11 ` [PULL 11/19] s390x/cpumodel: S390_FEAT_MISC_INSTRUCTION_EXT -> S390_FEAT_MISC_INSTRUCTION_EXT2 Cornelia Huck
2020-10-02 12:11 ` [PULL 12/19] s390x/tcg: Implement ADD HALFWORD (AGH) Cornelia Huck
2020-10-02 12:11 ` [PULL 13/19] s390x/tcg: Implement SUBTRACT HALFWORD (SGH) Cornelia Huck
2020-10-02 12:11 ` [PULL 14/19] s390x/tcg: Implement MULTIPLY (MG, MGRK) Cornelia Huck
2020-10-02 12:11 ` [PULL 15/19] s390x/tcg: Implement MULTIPLY HALFWORD (MGH) Cornelia Huck
2020-10-02 12:11 ` [PULL 16/19] s390x/tcg: Implement BRANCH INDIRECT ON CONDITION (BIC) Cornelia Huck
2020-10-02 12:11 ` [PULL 17/19] s390x/tcg: Implement MULTIPLY SINGLE (MSC, MSGC, MSGRKC, MSRKC) Cornelia Huck
2020-10-02 12:11 ` [PULL 18/19] s390x/tcg: We support Miscellaneous-Instruction-Extensions Facility 2 Cornelia Huck
2020-10-02 12:11 ` [PULL 19/19] s390x/tcg: Implement CIPHER MESSAGE WITH AUTHENTICATION (KMA) Cornelia Huck
2020-10-02 15:19 ` [PULL 00/19] s390x changes Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201002121118.180315-11-cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=farman@linux.ibm.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).