On Sat, Nov 01, 2014 at 06:02:27PM +0100, Marc Marí wrote: > Modularize functions in virtio-blk-test and add PCI suffix for PCI specific > components. > > Signed-off-by: Marc Marí <marc.mari.barc...@gmail.com> > --- > tests/virtio-blk-test.c | 57 > +++++++++++++++++++++++++++++++---------------- > 1 file changed, 38 insertions(+), 19 deletions(-) > > diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c > index 33e8094..6f07d5a 100644 > --- a/tests/virtio-blk-test.c > +++ b/tests/virtio-blk-test.c > @@ -55,11 +55,11 @@ typedef struct QVirtioBlkReq { > uint8_t status; > } QVirtioBlkReq; > > -static QPCIBus *test_start(void) > +static char *drive_create(void) > { > - char *cmdline; > - char tmp_path[] = "/tmp/qtest.XXXXXX"; > int fd, ret; > + char *tmp_path = malloc(18); > + strncpy(tmp_path, "/tmp/qtest.XXXXXX", 18);
Please use g_strdup(): https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strdup QEMU does not use malloc(3)/free(3) directly. Always use glib memory allocation (in this case g_strdup() allocates memory for you). > > /* Create a temporary raw image */ > fd = mkstemp(tmp_path); > @@ -68,6 +68,16 @@ static QPCIBus *test_start(void) > g_assert_cmpint(ret, ==, 0); > close(fd); > > + return tmp_path; > +} > + > +static QPCIBus *pci_test_start(void) > +{ > + char *cmdline; > + char *tmp_path; > + > + tmp_path = drive_create(); It seems tmp_path is leaked. You must free dynamically allocated memory!
pgpnRFgXfwmzk.pgp
Description: PGP signature