[PATCH] hw/i3c/dw-i3c: Fix memory leaks in error logging paths

Cédric Le Goater posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260309093838.364126-1-clg@redhat.com
Maintainers: Joe Komlodi <komlodi@google.com>, "Cédric Le Goater" <clg@kaod.org>, Jamin Lin <jamin_lin@aspeedtech.com>, Nabih Estefan <nabihestefan@google.com>
hw/i3c/dw-i3c.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] hw/i3c/dw-i3c: Fix memory leaks in error logging paths
Posted by Cédric Le Goater 1 month ago
object_get_canonical_path() returns an allocated string that must be
freed by the caller. Use g_autofree variables to ensure that memory is
not leaked.

Resolves: Coverity CID 1645550
Resolves: Coverity CID 1645553
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/i3c/dw-i3c.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c
index 3d8b95a14c4b..e9bdfd6af2ac 100644
--- a/hw/i3c/dw-i3c.c
+++ b/hw/i3c/dw-i3c.c
@@ -490,8 +490,9 @@ static int dw_i3c_recv_data(DWI3C *s, bool is_i2c, uint8_t *data,
     /* I3C devices can NACK if the controller sends an unsupported CCC. */
     ret = i3c_recv(s->bus, data, num_to_read, num_read);
     if (ret) {
+        g_autofree char *path = object_get_canonical_path(OBJECT(s));
         qemu_log_mask(LOG_GUEST_ERROR, "%s: NACKed receiving byte\n",
-                      object_get_canonical_path(OBJECT(s)));
+                      path);
         ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS,
                          DW_I3C_TRANSFER_STATE_HALT);
         ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_STATUS,
@@ -1107,8 +1108,9 @@ static void dw_i3c_resp_queue_push(DWI3C *s, uint8_t err, uint8_t tid,
 static void dw_i3c_push_tx(DWI3C *s, uint32_t val)
 {
     if (fifo32_is_full(&s->tx_queue)) {
+        g_autofree char *path = object_get_canonical_path(OBJECT(s));
         qemu_log_mask(LOG_GUEST_ERROR, "%s: Tried to push to TX FIFO when "
-                      "full\n", object_get_canonical_path(OBJECT(s)));
+                      "full\n", path);
         return;
     }
 
-- 
2.53.0


Re: [PATCH] hw/i3c/dw-i3c: Fix memory leaks in error logging paths
Posted by Philippe Mathieu-Daudé 1 month ago
On 9/3/26 10:38, Cédric Le Goater wrote:
> object_get_canonical_path() returns an allocated string that must be
> freed by the caller. Use g_autofree variables to ensure that memory is
> not leaked.
> 
> Resolves: Coverity CID 1645550
> Resolves: Coverity CID 1645553
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   hw/i3c/dw-i3c.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)

Patch queued via hw-misc, thanks.

Re: [PATCH] hw/i3c/dw-i3c: Fix memory leaks in error logging paths
Posted by Philippe Mathieu-Daudé 1 month ago
On 9/3/26 10:38, Cédric Le Goater wrote:
> object_get_canonical_path() returns an allocated string that must be
> freed by the caller. Use g_autofree variables to ensure that memory is
> not leaked.
> 
> Resolves: Coverity CID 1645550
> Resolves: Coverity CID 1645553
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   hw/i3c/dw-i3c.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>