On 7/14/20 6:02 PM, Markus Armbruster wrote:
> object_get_canonical_path_component() returns a malloced copy of a
> property name on success, null on failure.
> 
> 19 of its 25 callers immediately free the returned copy.
> 
> Change object_get_canonical_path_component() to return the property
> name directly.  Since modifying the name would be wrong, adjust the
> return type to const char *.

Yeah!

> 
> Drop the free from the 19 callers become simpler, add the g_strdup()
> to the other six.
> 
> Signed-off-by: Markus Armbruster <arm...@redhat.com>
> ---
>  include/qom/object.h       |  2 +-
>  backends/hostmem.c         |  2 +-
>  block/throttle-groups.c    |  2 +-
>  gdbstub.c                  |  2 +-
>  hw/arm/xlnx-zynqmp.c       |  6 ++----
>  hw/block/nvme.c            |  5 ++---
>  hw/core/machine-qmp-cmds.c |  2 +-
>  hw/core/machine.c          |  5 ++---
>  hw/mem/nvdimm.c            |  5 ++---
>  hw/mem/pc-dimm.c           |  5 ++---
>  hw/misc/ivshmem.c          |  5 ++---
>  hw/ppc/spapr_drc.c         |  3 +--
>  hw/virtio/virtio-crypto.c  |  5 ++---
>  hw/virtio/virtio-mem.c     |  6 ++----
>  hw/virtio/virtio-pmem.c    |  5 ++---
>  iothread.c                 |  9 ++++-----
>  net/net.c                  |  6 ++----
>  qom/object.c               |  7 +++----
>  qom/qom-hmp-cmds.c         | 11 ++++-------
>  scsi/pr-manager-helper.c   |  3 +--
>  scsi/pr-manager.c          |  2 +-
>  softmmu/memory.c           |  2 +-
>  hw/ppc/trace-events        |  2 +-
>  23 files changed, 41 insertions(+), 61 deletions(-)
...

> @@ -303,7 +302,7 @@ type_init(iothread_register_types)
>  
>  char *iothread_get_id(IOThread *iothread)
>  {
> -    return object_get_canonical_path_component(OBJECT(iothread));
> +    return g_strdup(object_get_canonical_path_component(OBJECT(iothread)));
>  }

(Note for later, this one can return const).

Reviewed-by: Philippe Mathieu-Daudé <phi...@redhat.com>


Reply via email to