From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH for-2.7 v3 17/36] machine: use class base init generated name
Date: Thu, 04 Aug 2016 17:26:21 +0200 [thread overview]
Message-ID: <87r3a4a736.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAJ+F1CLFUtaHJ3Mag5rOHOvY_kF0YyUt2w30SvFsAiASrabPTA@mail.gmail.com> ("Marc-André Lureau"'s message of "Thu, 04 Aug 2016 14:31:22 +0000")
Marc-André Lureau <marcandre.lureau@gmail.com> writes:
> Hi
>
> On Thu, Aug 4, 2016 at 5:58 PM Markus Armbruster <armbru@redhat.com> wrote:
>
>> marcandre.lureau@redhat.com writes:
>>
>> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> >
>> > Remove machine class name initialization from DEFINE_PC_MACHINE, rely on
>> > class base init name generation instead. Get rid of some leaks that way.
>> >
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > ---
>> > hw/core/machine.c | 1 +
>> > include/hw/boards.h | 2 +-
>> > include/hw/i386/pc.h | 1 -
>> > 3 files changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/hw/core/machine.c b/hw/core/machine.c
>> > index e5a456f..00fbe3e 100644
>> > --- a/hw/core/machine.c
>> > +++ b/hw/core/machine.c
>> > @@ -561,6 +561,7 @@ static void machine_class_finalize(ObjectClass *klass, void *data)
>> > if (mc->compat_props) {
>> > g_array_free(mc->compat_props, true);
>> > }
>> > + g_free(mc->name);
>> > }
>> >
>> > void machine_register_compat_props(MachineState *machine)
>> > diff --git a/include/hw/boards.h b/include/hw/boards.h
>> > index 3e69eca..e46a744 100644
>> > --- a/include/hw/boards.h
>> > +++ b/include/hw/boards.h
>> > @@ -93,7 +93,7 @@ struct MachineClass {
>> > /*< public >*/
>> >
>> > const char *family; /* NULL iff @name identifies a standalone machtype */
>> > - const char *name;
>> > + char *name;
>> > const char *alias;
>> > const char *desc;
>> >
>> > diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
>> > index eb1d414..afd025a 100644
>> > --- a/include/hw/i386/pc.h
>> > +++ b/include/hw/i386/pc.h
>> > @@ -903,7 +903,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
>> > { \
>> > MachineClass *mc = MACHINE_CLASS(oc); \
>> > optsfn(mc); \
>> > - mc->name = namestr; \
>> > mc->init = initfn; \
>> > } \
>> > static const TypeInfo pc_machine_type_##suffix = { \
>>
>> I guess there are is at least one assignment to mc->name not visible in
>> this patch that assigns an allocated string, which leaks before the
>> patch. The commit message seems to provide a clue "class base init name
>> generation". I could probably find it with some effort, but patches
>> that take that much work to understand make me grumpy. Please provide
>> another clue :)
>>
>
> Sorry, thanks for reminding me to write better commit messages.
Good commit messages are hard.
> git grep 'mc->name ='
> hw/core/machine.c: mc->name = g_strndup(cname,
Aha: the concrete machine type's init function overwrites the strdup()ed
value set by machine_class_base_init(), leaking it. Your fix removes
the overwrites and adds a free.
As far as I can see, you got all such overwrites.
> Is that better:
>
> Remove machine class name initialization from DEFINE_PC_MACHINE, rely on
> name generation from machine_class_base_init() instead, and free the
> corresponding allocation in machine_class_finalize().
Works for me. Alternatively:
machine_class_base_init() member name is allocated by
machine_class_base_init(), but not freed by machine_class_finalize().
Simply freeing there doesn't work, because DEFINE_PC_MACHINE()
overwrites it with a literal string.
Fix DEFINE_PC_MACHINE() not to overwrite it, and add the missing
free to machine_class_finalize().
Use the one you like better, or mix them up to taste.
Reviewed-by: Markus Armbruster <armbru@redhat.com>
next prev parent reply other threads:[~2016-08-04 15:26 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-03 14:55 [Qemu-devel] [PATCH for-2.7 v3 00/36] Various memory leak fixes marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 01/36] build-sys: fix building with make CFLAGS=.. argument marcandre.lureau
2016-08-03 15:58 ` Paolo Bonzini
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 02/36] tests: fix test-qga leaks marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 03/36] qga: free the whole blacklist marcandre.lureau
2016-08-04 13:25 ` Markus Armbruster
2016-08-04 13:47 ` Marc-André Lureau
2016-08-04 14:39 ` Markus Armbruster
2016-08-04 14:59 ` Marc-André Lureau
2016-08-05 7:06 ` Markus Armbruster
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 04/36] qga: free remaining leaking state marcandre.lureau
2016-08-04 13:38 ` Markus Armbruster
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 05/36] tests: fix test-cutils leaks marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 06/36] tests: fix test-vmstate leaks marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 07/36] tests: fix test-iov leaks marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 08/36] qdist: fix entries memory leak marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 09/36] tests: fix check-qom-interface leaks marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 10/36] tests: fix check-qom-proplist leaks marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 11/36] tests: fix small leak in test-io-channel-command marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 12/36] tests: fix leak in test-string-input-visitor marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 13/36] portio: keep references on portio marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 14/36] numa: do not leak NumaOptions marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 15/36] pc: simplify passing qemu_irq marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 16/36] pc: don't leak a20_line marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 17/36] machine: use class base init generated name marcandre.lureau
2016-08-04 13:56 ` Markus Armbruster
2016-08-04 14:31 ` Marc-André Lureau
2016-08-04 15:26 ` Markus Armbruster [this message]
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 18/36] acpi-build: fix array leak marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 19/36] char: free the tcp connection data when closing marcandre.lureau
2016-08-03 15:32 ` Paolo Bonzini
2016-08-03 15:40 ` Marc-André Lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 20/36] char: free MuxDriver " marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 21/36] tests: fix qom-test leaks marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 22/36] pc: free i8259 marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 23/36] pc: keep gsi reference marcandre.lureau
2016-08-04 14:45 ` Markus Armbruster
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 24/36] ahci: free irqs array marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 25/36] sd: free timer marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 26/36] qjson: free str marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 27/36] virtio-input: free config list marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 28/36] ipmi: free extern timer marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 29/36] usb: free USBDevice.strings marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 30/36] usb: free leaking path marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 31/36] bus: simplify name handling marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 32/36] tests: add qtest_add_data_func_full marcandre.lureau
2016-08-04 14:54 ` Markus Armbruster
2016-08-04 15:05 ` Marc-André Lureau
2016-08-05 7:12 ` Markus Armbruster
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 33/36] tests: pc-cpu-test leaks fixes marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 34/36] tests: fix rsp leak in postcopy-test marcandre.lureau
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 35/36] ahci: fix sglist leak on retry marcandre.lureau
2016-08-04 14:46 ` Markus Armbruster
2016-08-04 21:16 ` John Snow
2016-08-03 14:55 ` [Qemu-devel] [PATCH for-2.7 v3 36/36] tests: fix postcopy-test leaks marcandre.lureau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r3a4a736.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.