* Re: [Qemu-devel] [PATCH 3/3] hw/machine: Free old values of string properties [not found] ` <1401480140-18653-4-git-send-email-ehabkost@redhat.com> @ 2014-06-01 8:25 ` Marcel Apfelbaum 2014-06-02 11:51 ` Markus Armbruster 0 siblings, 1 reply; 11+ messages in thread From: Marcel Apfelbaum @ 2014-06-01 8:25 UTC (permalink / raw) To: Eduardo Habkost, Luiz Capitulino, Markus Armbruster Cc: qemu-devel, Andreas Färber On Fri, 2014-05-30 at 17:02 -0300, Eduardo Habkost wrote: > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: Marcel Apfelbaum <marcel.a@redhat.com> > Cc: Andreas Färber <afaerber@suse.de> > --- > hw/core/machine.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/hw/core/machine.c b/hw/core/machine.c > index cbba679..df612bb 100644 > --- a/hw/core/machine.c > +++ b/hw/core/machine.c > @@ -24,6 +24,7 @@ static void machine_set_accel(Object *obj, const char *value, Error **errp) > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->accel); I am not sure if in QMP is not caller's responsibility to free the input string. If I think about it, I ask an object to set "my" string and it deletes it :(... Same for the others. Added Markus and Luiz, maybe they have an opinion on that. Thanks, Marcel > ms->accel = g_strdup(value); > } > > @@ -79,6 +80,7 @@ static void machine_set_kernel(Object *obj, const char *value, Error **errp) > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->kernel_filename); > ms->kernel_filename = g_strdup(value); > } > > @@ -93,6 +95,7 @@ static void machine_set_initrd(Object *obj, const char *value, Error **errp) > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->initrd_filename); > ms->initrd_filename = g_strdup(value); > } > > @@ -107,6 +110,7 @@ static void machine_set_append(Object *obj, const char *value, Error **errp) > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->kernel_cmdline); > ms->kernel_cmdline = g_strdup(value); > } > > @@ -121,6 +125,7 @@ static void machine_set_dtb(Object *obj, const char *value, Error **errp) > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->dtb); > ms->dtb = g_strdup(value); > } > > @@ -135,6 +140,7 @@ static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->dumpdtb); > ms->dumpdtb = g_strdup(value); > } > > @@ -176,6 +182,7 @@ static void machine_set_dt_compatible(Object *obj, const char *value, Error **er > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->dt_compatible); > ms->dt_compatible = g_strdup(value); > } > > @@ -232,6 +239,7 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) > { > MachineState *ms = MACHINE(obj); > > + g_free(ms->firmware); > ms->firmware = g_strdup(value); > } > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 3/3] hw/machine: Free old values of string properties 2014-06-01 8:25 ` [Qemu-devel] [PATCH 3/3] hw/machine: Free old values of string properties Marcel Apfelbaum @ 2014-06-02 11:51 ` Markus Armbruster 2014-06-02 12:13 ` Marcel Apfelbaum 0 siblings, 1 reply; 11+ messages in thread From: Markus Armbruster @ 2014-06-02 11:51 UTC (permalink / raw) To: Marcel Apfelbaum Cc: Luiz Capitulino, Eduardo Habkost, Andreas Färber, qemu-devel Marcel Apfelbaum <marcel.a@redhat.com> writes: > On Fri, 2014-05-30 at 17:02 -0300, Eduardo Habkost wrote: >> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> >> --- >> Cc: Marcel Apfelbaum <marcel.a@redhat.com> >> Cc: Andreas Färber <afaerber@suse.de> >> --- >> hw/core/machine.c | 8 ++++++++ >> 1 file changed, 8 insertions(+) >> >> diff --git a/hw/core/machine.c b/hw/core/machine.c >> index cbba679..df612bb 100644 >> --- a/hw/core/machine.c >> +++ b/hw/core/machine.c >> @@ -24,6 +24,7 @@ static void machine_set_accel(Object *obj, const char *value, Error **errp) >> { >> MachineState *ms = MACHINE(obj); >> >> + g_free(ms->accel); > I am not sure if in QMP is not caller's responsibility to free the input string. > If I think about it, I ask an object to set "my" string and it deletes it :(... > Same for the others. > > Added Markus and Luiz, maybe they have an opinion on that. > >> ms->accel = g_strdup(value); >> } >> Misunderstanding? Eduardo's patch frees the old value before it overwrites it. It doesn't free "the input string", assuming by "the input string" you mean argument value. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 3/3] hw/machine: Free old values of string properties 2014-06-02 11:51 ` Markus Armbruster @ 2014-06-02 12:13 ` Marcel Apfelbaum 2014-06-02 12:52 ` Markus Armbruster 0 siblings, 1 reply; 11+ messages in thread From: Marcel Apfelbaum @ 2014-06-02 12:13 UTC (permalink / raw) To: Markus Armbruster Cc: Luiz Capitulino, Eduardo Habkost, Andreas Färber, qemu-devel On Mon, 2014-06-02 at 13:51 +0200, Markus Armbruster wrote: > Marcel Apfelbaum <marcel.a@redhat.com> writes: > > > On Fri, 2014-05-30 at 17:02 -0300, Eduardo Habkost wrote: > >> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > >> --- > >> Cc: Marcel Apfelbaum <marcel.a@redhat.com> > >> Cc: Andreas Färber <afaerber@suse.de> > >> --- > >> hw/core/machine.c | 8 ++++++++ > >> 1 file changed, 8 insertions(+) > >> > >> diff --git a/hw/core/machine.c b/hw/core/machine.c > >> index cbba679..df612bb 100644 > >> --- a/hw/core/machine.c > >> +++ b/hw/core/machine.c > >> @@ -24,6 +24,7 @@ static void machine_set_accel(Object *obj, const char *value, Error **errp) > >> { > >> MachineState *ms = MACHINE(obj); > >> > >> + g_free(ms->accel); > > I am not sure if in QMP is not caller's responsibility to free the input string. > > If I think about it, I ask an object to set "my" string and it deletes it :(... > > Same for the others. > > > > Added Markus and Luiz, maybe they have an opinion on that. > > > >> ms->accel = g_strdup(value); > >> } > >> > > Misunderstanding? Eduardo's patch frees the old value before it > overwrites it. It doesn't free "the input string", assuming by "the > input string" you mean argument value. You are right! My bad, for some reason I saw g_free(value), but it was me not reading it right :(. Thanks, Marcel ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 3/3] hw/machine: Free old values of string properties 2014-06-02 12:13 ` Marcel Apfelbaum @ 2014-06-02 12:52 ` Markus Armbruster 2014-06-02 14:33 ` Marcel Apfelbaum 0 siblings, 1 reply; 11+ messages in thread From: Markus Armbruster @ 2014-06-02 12:52 UTC (permalink / raw) To: Marcel Apfelbaum Cc: qemu-devel, Luiz Capitulino, Eduardo Habkost, Andreas Färber Marcel Apfelbaum <marcel.a@redhat.com> writes: > On Mon, 2014-06-02 at 13:51 +0200, Markus Armbruster wrote: >> Marcel Apfelbaum <marcel.a@redhat.com> writes: >> >> > On Fri, 2014-05-30 at 17:02 -0300, Eduardo Habkost wrote: >> >> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> >> >> --- >> >> Cc: Marcel Apfelbaum <marcel.a@redhat.com> >> >> Cc: Andreas Färber <afaerber@suse.de> >> >> --- >> >> hw/core/machine.c | 8 ++++++++ >> >> 1 file changed, 8 insertions(+) >> >> >> >> diff --git a/hw/core/machine.c b/hw/core/machine.c >> >> index cbba679..df612bb 100644 >> >> --- a/hw/core/machine.c >> >> +++ b/hw/core/machine.c >> >> @@ -24,6 +24,7 @@ static void machine_set_accel(Object *obj, const char *value, Error **errp) >> >> { >> >> MachineState *ms = MACHINE(obj); >> >> >> >> + g_free(ms->accel); >> > I am not sure if in QMP is not caller's responsibility to free the >> > input string. >> > If I think about it, I ask an object to set "my" string and it >> > deletes it :(... >> > Same for the others. >> > >> > Added Markus and Luiz, maybe they have an opinion on that. >> > >> >> ms->accel = g_strdup(value); >> >> } >> >> >> >> Misunderstanding? Eduardo's patch frees the old value before it >> overwrites it. It doesn't free "the input string", assuming by "the >> input string" you mean argument value. > > You are right! My bad, for some reason I saw g_free(value), but it > was me not reading it right :(. Happens :) Reviewed-by: Markus Armbruster <armbru@redhat.com> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 3/3] hw/machine: Free old values of string properties 2014-06-02 12:52 ` Markus Armbruster @ 2014-06-02 14:33 ` Marcel Apfelbaum 0 siblings, 0 replies; 11+ messages in thread From: Marcel Apfelbaum @ 2014-06-02 14:33 UTC (permalink / raw) To: Markus Armbruster Cc: qemu-devel, Luiz Capitulino, Eduardo Habkost, Andreas Färber On Mon, 2014-06-02 at 14:52 +0200, Markus Armbruster wrote: > Marcel Apfelbaum <marcel.a@redhat.com> writes: > > > On Mon, 2014-06-02 at 13:51 +0200, Markus Armbruster wrote: > >> Marcel Apfelbaum <marcel.a@redhat.com> writes: > >> > >> > On Fri, 2014-05-30 at 17:02 -0300, Eduardo Habkost wrote: > >> >> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > >> >> --- > >> >> Cc: Marcel Apfelbaum <marcel.a@redhat.com> > >> >> Cc: Andreas Färber <afaerber@suse.de> > >> >> --- > >> >> hw/core/machine.c | 8 ++++++++ > >> >> 1 file changed, 8 insertions(+) > >> >> > >> >> diff --git a/hw/core/machine.c b/hw/core/machine.c > >> >> index cbba679..df612bb 100644 > >> >> --- a/hw/core/machine.c > >> >> +++ b/hw/core/machine.c > >> >> @@ -24,6 +24,7 @@ static void machine_set_accel(Object *obj, const char *value, Error **errp) > >> >> { > >> >> MachineState *ms = MACHINE(obj); > >> >> > >> >> + g_free(ms->accel); > >> > I am not sure if in QMP is not caller's responsibility to free the > >> > input string. > >> > If I think about it, I ask an object to set "my" string and it > >> > deletes it :(... > >> > Same for the others. > >> > > >> > Added Markus and Luiz, maybe they have an opinion on that. > >> > > >> >> ms->accel = g_strdup(value); > >> >> } > >> >> > >> > >> Misunderstanding? Eduardo's patch frees the old value before it > >> overwrites it. It doesn't free "the input string", assuming by "the > >> input string" you mean argument value. > > > > You are right! My bad, for some reason I saw g_free(value), but it > > was me not reading it right :(. > > Happens :) > > Reviewed-by: Markus Armbruster <armbru@redhat.com> Yes indeed. Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com> ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <1401480140-18653-2-git-send-email-ehabkost@redhat.com>]
* Re: [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free() [not found] ` <1401480140-18653-2-git-send-email-ehabkost@redhat.com> @ 2014-06-02 11:38 ` Markus Armbruster 2014-08-07 2:19 ` Amos Kong 2014-06-09 20:04 ` Luiz Capitulino 1 sibling, 1 reply; 11+ messages in thread From: Markus Armbruster @ 2014-06-02 11:38 UTC (permalink / raw) To: Eduardo Habkost Cc: Marcel Apfelbaum, Luiz Capitulino, qemu-devel, Anthony Liguori, Andreas Färber Eduardo Habkost <ehabkost@redhat.com> writes: > g_free() is NULL-safe. > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: Anthony Liguori <aliguori@amazon.com> > Cc: Luiz Capitulino <lcapitulino@redhat.com> > --- > backends/rng-random.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/backends/rng-random.c b/backends/rng-random.c > index 136499d..601d9dc 100644 > --- a/backends/rng-random.c > +++ b/backends/rng-random.c > @@ -106,10 +106,7 @@ static void rng_random_set_filename(Object *obj, const char *filename, > return; > } > > - if (s->filename) { > - g_free(s->filename); > - } > - > + g_free(s->filename); > s->filename = g_strdup(filename); > } Reviewed-by: Markus Armbruster <armbru@redhat.com> Note there are a quite a few more instances of this anti-pattern. Coccinelle can find them, semantic patch appended. Beware, it can throw away comments in the conditional, which is usually not what we want. @@ expression E; @@ - if (E != NULL) { - g_free(E); - } + g_free(E); ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free() 2014-06-02 11:38 ` [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free() Markus Armbruster @ 2014-08-07 2:19 ` Amos Kong 0 siblings, 0 replies; 11+ messages in thread From: Amos Kong @ 2014-08-07 2:19 UTC (permalink / raw) To: Markus Armbruster Cc: Eduardo Habkost, Marcel Apfelbaum, qemu-devel, Luiz Capitulino, Anthony Liguori, Andreas Färber On Mon, Jun 02, 2014 at 01:38:52PM +0200, Markus Armbruster wrote: > Eduardo Habkost <ehabkost@redhat.com> writes: > > > g_free() is NULL-safe. > > > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > > --- > > Cc: Anthony Liguori <aliguori@amazon.com> > > Cc: Luiz Capitulino <lcapitulino@redhat.com> > > --- > > backends/rng-random.c | 5 +---- > > 1 file changed, 1 insertion(+), 4 deletions(-) > > > > diff --git a/backends/rng-random.c b/backends/rng-random.c > > index 136499d..601d9dc 100644 > > --- a/backends/rng-random.c > > +++ b/backends/rng-random.c > > @@ -106,10 +106,7 @@ static void rng_random_set_filename(Object *obj, const char *filename, > > return; > > } > > > > - if (s->filename) { > > - g_free(s->filename); > > - } > > - > > + g_free(s->filename); > > s->filename = g_strdup(filename); > > } > > Reviewed-by: Markus Armbruster <armbru@redhat.com> > > > Note there are a quite a few more instances of this anti-pattern. > Coccinelle can find them, semantic patch appended. Beware, it can throw > away comments in the conditional, which is usually not what we want. > > > @@ > expression E; > @@ > - if (E != NULL) { > - g_free(E); > - } > + g_free(E); [amos@z qemu]$ grep g_free -B 2 -r * |less then try to search "/if.*NULL" Not all can be found by this way, but many instances are found. -- Amos. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free() [not found] ` <1401480140-18653-2-git-send-email-ehabkost@redhat.com> 2014-06-02 11:38 ` [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free() Markus Armbruster @ 2014-06-09 20:04 ` Luiz Capitulino 2014-06-21 15:06 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev 1 sibling, 1 reply; 11+ messages in thread From: Luiz Capitulino @ 2014-06-09 20:04 UTC (permalink / raw) To: Eduardo Habkost Cc: qemu-trivial, Marcel Apfelbaum, qemu-devel, Anthony Liguori, Andreas Färber On Fri, 30 May 2014 17:02:18 -0300 Eduardo Habkost <ehabkost@redhat.com> wrote: > g_free() is NULL-safe. > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> This one should to go through qemu-trivial (CCed). > --- > Cc: Anthony Liguori <aliguori@amazon.com> > Cc: Luiz Capitulino <lcapitulino@redhat.com> > --- > backends/rng-random.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/backends/rng-random.c b/backends/rng-random.c > index 136499d..601d9dc 100644 > --- a/backends/rng-random.c > +++ b/backends/rng-random.c > @@ -106,10 +106,7 @@ static void rng_random_set_filename(Object *obj, const char *filename, > return; > } > > - if (s->filename) { > - g_free(s->filename); > - } > - > + g_free(s->filename); > s->filename = g_strdup(filename); > } > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH 1/3] rng-random: NULL check not needed before g_free() 2014-06-09 20:04 ` Luiz Capitulino @ 2014-06-21 15:06 ` Michael Tokarev 0 siblings, 0 replies; 11+ messages in thread From: Michael Tokarev @ 2014-06-21 15:06 UTC (permalink / raw) To: Luiz Capitulino, Eduardo Habkost Cc: qemu-trivial, Andreas Färber, qemu-devel, Anthony Liguori, Marcel Apfelbaum 10.06.2014 00:04, Luiz Capitulino wrote: > On Fri, 30 May 2014 17:02:18 -0300 > Eduardo Habkost <ehabkost@redhat.com> wrote: > >> g_free() is NULL-safe. Applied to -trivial, thank you! /mjt ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <1401480140-18653-3-git-send-email-ehabkost@redhat.com>]
* Re: [Qemu-devel] [PATCH 2/3] rng-egd: Free old chr_name value before setting new one [not found] ` <1401480140-18653-3-git-send-email-ehabkost@redhat.com> @ 2014-06-02 12:58 ` Markus Armbruster 2014-06-02 14:50 ` Eduardo Habkost 0 siblings, 1 reply; 11+ messages in thread From: Markus Armbruster @ 2014-06-02 12:58 UTC (permalink / raw) To: Eduardo Habkost Cc: Marcel Apfelbaum, Amos Kong, qemu-devel, Anthony Liguori, Andreas Färber Eduardo Habkost <ehabkost@redhat.com> writes: > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > Cc: Anthony Liguori <aliguori@amazon.com> > Cc: Amos Kong <akong@redhat.com> > --- > backends/rng-egd.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/backends/rng-egd.c b/backends/rng-egd.c > index 25bb3b4..2962795 100644 > --- a/backends/rng-egd.c > +++ b/backends/rng-egd.c > @@ -169,6 +169,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp) > if (b->opened) { > error_set(errp, QERR_PERMISSION_DENIED); > } else { > + g_free(s->chr_name); > s->chr_name = g_strdup(value); > } > } I see you searched for the bug elsewhere. Appreciated. Do you think you got them all? Aside: I hate if (bad) { handle error } else { continue normal work } The normal flow gets nested deeper and deeper. When the code grows, normal work can easily end up after the conditional by mistake. Better: if (bad) { handle error return } continue normal work Anyway, not your fault. Reviewed-by: Markus Armbruster <armbru@redhat.com> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 2/3] rng-egd: Free old chr_name value before setting new one 2014-06-02 12:58 ` [Qemu-devel] [PATCH 2/3] rng-egd: Free old chr_name value before setting new one Markus Armbruster @ 2014-06-02 14:50 ` Eduardo Habkost 0 siblings, 0 replies; 11+ messages in thread From: Eduardo Habkost @ 2014-06-02 14:50 UTC (permalink / raw) To: Markus Armbruster Cc: Marcel Apfelbaum, Amos Kong, qemu-devel, Anthony Liguori, Andreas Färber On Mon, Jun 02, 2014 at 02:58:05PM +0200, Markus Armbruster wrote: > Eduardo Habkost <ehabkost@redhat.com> writes: > > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > > --- > > Cc: Anthony Liguori <aliguori@amazon.com> > > Cc: Amos Kong <akong@redhat.com> > > --- > > backends/rng-egd.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/backends/rng-egd.c b/backends/rng-egd.c > > index 25bb3b4..2962795 100644 > > --- a/backends/rng-egd.c > > +++ b/backends/rng-egd.c > > @@ -169,6 +169,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp) > > if (b->opened) { > > error_set(errp, QERR_PERMISSION_DENIED); > > } else { > > + g_free(s->chr_name); > > s->chr_name = g_strdup(value); > > } > > } > > I see you searched for the bug elsewhere. Appreciated. Do you think > you got them all? I grepped for all object_property_add_str occurrences, and (unless I made a mistake) I fixed all of them. -- Eduardo ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-08-07 2:20 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <1401480140-18653-1-git-send-email-ehabkost@redhat.com> [not found] ` <1401480140-18653-4-git-send-email-ehabkost@redhat.com> 2014-06-01 8:25 ` [Qemu-devel] [PATCH 3/3] hw/machine: Free old values of string properties Marcel Apfelbaum 2014-06-02 11:51 ` Markus Armbruster 2014-06-02 12:13 ` Marcel Apfelbaum 2014-06-02 12:52 ` Markus Armbruster 2014-06-02 14:33 ` Marcel Apfelbaum [not found] ` <1401480140-18653-2-git-send-email-ehabkost@redhat.com> 2014-06-02 11:38 ` [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free() Markus Armbruster 2014-08-07 2:19 ` Amos Kong 2014-06-09 20:04 ` Luiz Capitulino 2014-06-21 15:06 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev [not found] ` <1401480140-18653-3-git-send-email-ehabkost@redhat.com> 2014-06-02 12:58 ` [Qemu-devel] [PATCH 2/3] rng-egd: Free old chr_name value before setting new one Markus Armbruster 2014-06-02 14:50 ` Eduardo Habkost
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).