hw/i2c/bitbang_i2c: Use in-place rather than malloc'd bitbang_i2c_interface struct
commit41742927ee37527462a13160380860653d4f1c84
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 2 Jul 2019 16:38:44 +0000 (2 17:38 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 3 Jul 2019 08:51:35 +0000 (3 10:51 +0200)
tree41744da1198ff76741c61bba6a7aa33e95b59f04
parentb0ee78ff31617937f44161bde7515a67c88748c7
hw/i2c/bitbang_i2c: Use in-place rather than malloc'd bitbang_i2c_interface struct

Currently the bitbang_i2c_init() function allocates a
bitbang_i2c_interface struct which it returns.  This is unfortunate
because it means that if the function is used from a DeviceState
init method then the memory will be leaked by an "init then delete"
cycle, as used by the qmp/hmp commands that list device properties.

Since three out of four of the uses of this function are in
device init methods, switch the function to do an in-place
initialization of a struct that can be embedded in the
device state struct of the caller.

This fixes LeakSanitizer leak warnings that have appeared in the
patchew configuration (which only tries to run the sanitizers
for the x86_64-softmmu target) now that we use the bitbang-i2c
code in an x86-64 config.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu>
Tested-by: BALATON Zoltan <balaton@eik.bme.hu>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20190702163844.20458-1-peter.maydell@linaro.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/display/ati.c
hw/display/ati_int.h
hw/i2c/bitbang_i2c.c
hw/i2c/ppc4xx_i2c.c
hw/i2c/versatile_i2c.c
include/hw/i2c/bitbang_i2c.h
include/hw/i2c/ppc4xx_i2c.h