* [PULL 1/4] qemu/osdep: Document os_find_datadir() return value
2020-07-21 18:01 [PULL 0/4] AVR patches for 2020-07-21 Philippe Mathieu-Daudé
@ 2020-07-21 18:01 ` Philippe Mathieu-Daudé
2020-07-21 18:01 ` [PULL 2/4] qemu/osdep: Reword qemu_get_exec_dir() documentation Philippe Mathieu-Daudé
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-21 18:01 UTC (permalink / raw)
To: qemu-devel
Cc: Sarah Harris, Daniel P . Berrangé, Stefan Weil,
Philippe Mathieu-Daudé, Michael Rolnik, Paolo Bonzini
Document os_find_datadir() returned data must be freed.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Tested-by: Michael Rolnik <mrolnik@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200714164257.23330-2-f4bug@amsat.org>
---
os-posix.c | 3 +++
os-win32.c | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/os-posix.c b/os-posix.c
index b674b20b1b..3572db3f44 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -84,6 +84,9 @@ void os_setup_signal_handling(void)
* Find a likely location for support files using the location of the binary.
* When running from the build tree this will be "$bindir/../pc-bios".
* Otherwise, this is CONFIG_QEMU_DATADIR.
+ *
+ * The caller must use g_free() to free the returned data when it is
+ * no longer required.
*/
char *os_find_datadir(void)
{
diff --git a/os-win32.c b/os-win32.c
index 6b86e022f0..c9c3afe648 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -57,7 +57,12 @@ void os_setup_early_signal_handling(void)
atexit(os_undo_timer_resolution);
}
-/* Look for support files in the same directory as the executable. */
+/*
+ * Look for support files in the same directory as the executable.
+ *
+ * The caller must use g_free() to free the returned data when it is
+ * no longer required.
+ */
char *os_find_datadir(void)
{
return qemu_get_exec_dir();
--
2.21.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PULL 2/4] qemu/osdep: Reword qemu_get_exec_dir() documentation
2020-07-21 18:01 [PULL 0/4] AVR patches for 2020-07-21 Philippe Mathieu-Daudé
2020-07-21 18:01 ` [PULL 1/4] qemu/osdep: Document os_find_datadir() return value Philippe Mathieu-Daudé
@ 2020-07-21 18:01 ` Philippe Mathieu-Daudé
2020-07-21 18:01 ` [PULL 3/4] qemu-common: Document qemu_find_file() Philippe Mathieu-Daudé
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-21 18:01 UTC (permalink / raw)
To: qemu-devel
Cc: Sarah Harris, Daniel P . Berrangé, Stefan Weil,
Philippe Mathieu-Daudé, Michael Rolnik, Paolo Bonzini
This comment is confuse, reword it a bit.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Tested-by: Michael Rolnik <mrolnik@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200714164257.23330-3-f4bug@amsat.org>
---
include/qemu/osdep.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 4841b5c6b5..45c217aa28 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -588,7 +588,10 @@ char *qemu_get_local_state_pathname(const char *relative_pathname);
void qemu_init_exec_dir(const char *argv0);
/* Get the saved exec dir.
- * Caller needs to release the returned string by g_free() */
+ *
+ * The caller is responsible for releasing the value returned with g_free()
+ * after use.
+ */
char *qemu_get_exec_dir(void);
/**
--
2.21.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PULL 3/4] qemu-common: Document qemu_find_file()
2020-07-21 18:01 [PULL 0/4] AVR patches for 2020-07-21 Philippe Mathieu-Daudé
2020-07-21 18:01 ` [PULL 1/4] qemu/osdep: Document os_find_datadir() return value Philippe Mathieu-Daudé
2020-07-21 18:01 ` [PULL 2/4] qemu/osdep: Reword qemu_get_exec_dir() documentation Philippe Mathieu-Daudé
@ 2020-07-21 18:01 ` Philippe Mathieu-Daudé
2020-07-21 18:01 ` [PULL 4/4] hw/avr/boot: Fix memory leak in avr_load_firmware() Philippe Mathieu-Daudé
2020-07-23 12:38 ` [PULL 0/4] AVR patches for 2020-07-21 Peter Maydell
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-21 18:01 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Sarah Harris, Daniel P . Berrangé,
Stefan Weil, Li Qiang, Philippe Mathieu-Daudé,
Michael Rolnik, Paolo Bonzini
Document qemu_find_file(), in particular the returned
value which must be freed.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Tested-by: Michael Rolnik <mrolnik@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200714164257.23330-4-f4bug@amsat.org>
---
include/qemu-common.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/qemu-common.h b/include/qemu-common.h
index d0142f29ac..bb9496bd80 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -110,6 +110,23 @@ const char *qemu_get_vm_name(void);
#define QEMU_FILE_TYPE_BIOS 0
#define QEMU_FILE_TYPE_KEYMAP 1
+/**
+ * qemu_find_file:
+ * @type: QEMU_FILE_TYPE_BIOS (for BIOS, VGA BIOS)
+ * or QEMU_FILE_TYPE_KEYMAP (for keymaps).
+ * @name: Relative or absolute file name
+ *
+ * If @name exists on disk as an absolute path, or a path relative
+ * to the current directory, then returns @name unchanged.
+ * Otherwise searches for @name file in the data directories, either
+ * configured at build time (DATADIR) or registered with the -L command
+ * line option.
+ *
+ * The caller must use g_free() to free the returned data when it is
+ * no longer required.
+ *
+ * Returns: a path that can access @name, or NULL if no matching file exists.
+ */
char *qemu_find_file(int type, const char *name);
/* OS specific functions */
--
2.21.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PULL 4/4] hw/avr/boot: Fix memory leak in avr_load_firmware()
2020-07-21 18:01 [PULL 0/4] AVR patches for 2020-07-21 Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2020-07-21 18:01 ` [PULL 3/4] qemu-common: Document qemu_find_file() Philippe Mathieu-Daudé
@ 2020-07-21 18:01 ` Philippe Mathieu-Daudé
2020-07-23 12:38 ` [PULL 0/4] AVR patches for 2020-07-21 Peter Maydell
4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-21 18:01 UTC (permalink / raw)
To: qemu-devel
Cc: Sarah Harris, Daniel P . Berrangé, Stefan Weil,
Philippe Mathieu-Daudé, Michael Rolnik, Paolo Bonzini
The value returned by qemu_find_file() must be freed.
This fixes Coverity issue CID 1430449, which points out
that the memory returned by qemu_find_file() is leaked.
Fixes: Coverity CID 1430449 (RESOURCE_LEAK)
Fixes: 7dd8f6fde4 ('hw/avr: Add support for loading ELF/raw binaries')
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Tested-by: Michael Rolnik <mrolnik@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200714164257.23330-5-f4bug@amsat.org>
---
hw/avr/boot.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/avr/boot.c b/hw/avr/boot.c
index 6fbcde4061..d16bb3dbe1 100644
--- a/hw/avr/boot.c
+++ b/hw/avr/boot.c
@@ -60,7 +60,7 @@ static const char *avr_elf_e_flags_to_cpu_type(uint32_t flags)
bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
MemoryRegion *program_mr, const char *firmware)
{
- const char *filename;
+ g_autofree char *filename = NULL;
int bytes_loaded;
uint64_t entry;
uint32_t e_flags;
--
2.21.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PULL 0/4] AVR patches for 2020-07-21
2020-07-21 18:01 [PULL 0/4] AVR patches for 2020-07-21 Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2020-07-21 18:01 ` [PULL 4/4] hw/avr/boot: Fix memory leak in avr_load_firmware() Philippe Mathieu-Daudé
@ 2020-07-23 12:38 ` Peter Maydell
4 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2020-07-23 12:38 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Stefan Weil, Sarah Harris, Michael Rolnik, QEMU Developers,
Paolo Bonzini
On Tue, 21 Jul 2020 at 19:03, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> The following changes since commit 90218a9a393c7925f330e7dcc08658e2a01d3bd4:
>
> Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-07=
> -21' into staging (2020-07-21 10:24:38 +0100)
>
> are available in the Git repository at:
>
> https://gitlab.com/philmd/qemu.git tags/avr-20200721
>
> for you to fetch changes up to 5e29521a82e540552880c3572cb8274bcaa1002c:
>
> hw/avr/boot: Fix memory leak in avr_load_firmware() (2020-07-21 16:13:04 +0=
> 200)
>
> ----------------------------------------------------------------
> AVR patches
>
> Fixes a memory leak reported by Coverity (CID 1430449).
>
> CI jobs result:
> . https://gitlab.com/philmd/qemu/-/pipelines/168722631
>
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread