From: Laurent Vivier <laurent@vivier.eu>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: pavel.dovgaluk@ispras.ru, pbonzini@redhat.com,
mtosatti@redhat.com, sunilmut@microsoft.com,
qemu-trivial@nongnu.org
Subject: Re: [PATCH] Drop superfluous conditionals around g_free()
Date: Thu, 29 Sep 2022 21:28:58 +0200 [thread overview]
Message-ID: <cbc7643d-40e3-a083-828a-2fafd79f34d2@vivier.eu> (raw)
In-Reply-To: <20220923090428.93529-1-armbru@redhat.com>
Le 23/09/2022 à 11:04, Markus Armbruster a écrit :
> There is no need to guard g_free(P) with if (P): g_free(NULL) is safe.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> replay/replay.c | 6 ++----
> target/i386/kvm/kvm.c | 12 ++++--------
> target/i386/whpx/whpx-all.c | 14 ++++++--------
> 3 files changed, 12 insertions(+), 20 deletions(-)
>
> diff --git a/replay/replay.c b/replay/replay.c
> index 4c396bb376..9a0dc1cf44 100644
> --- a/replay/replay.c
> +++ b/replay/replay.c
> @@ -366,10 +366,8 @@ void replay_finish(void)
> fclose(replay_file);
> replay_file = NULL;
> }
> - if (replay_filename) {
> - g_free(replay_filename);
> - replay_filename = NULL;
> - }
> + g_free(replay_filename);
> + replay_filename = NULL;
>
> g_free(replay_snapshot);
> replay_snapshot = NULL;
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index a1fd1f5379..9603bf265a 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -2176,15 +2176,11 @@ int kvm_arch_destroy_vcpu(CPUState *cs)
>
> g_free(env->xsave_buf);
>
> - if (cpu->kvm_msr_buf) {
> - g_free(cpu->kvm_msr_buf);
> - cpu->kvm_msr_buf = NULL;
> - }
> + g_free(cpu->kvm_msr_buf);
> + cpu->kvm_msr_buf = NULL;
>
> - if (env->nested_state) {
> - g_free(env->nested_state);
> - env->nested_state = NULL;
> - }
> + g_free(env->nested_state);
> + env->nested_state = NULL;
>
> qemu_del_vm_change_state_handler(cpu->vmsentry);
>
> diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
> index b22a3314b4..8e4969edeb 100644
> --- a/target/i386/whpx/whpx-all.c
> +++ b/target/i386/whpx/whpx-all.c
> @@ -1225,14 +1225,12 @@ static void whpx_translate_cpu_breakpoints(
> }
> }
>
> - if (breakpoints->breakpoints) {
> - /*
> - * Free the previous breakpoint list. This can be optimized by keeping
> - * it as shadow buffer for the next computation instead of freeing
> - * it immediately.
> - */
> - g_free(breakpoints->breakpoints);
> - }
> + /*
> + * Free the previous breakpoint list. This can be optimized by keeping
> + * it as shadow buffer for the next computation instead of freeing
> + * it immediately.
> + */
> + g_free(breakpoints->breakpoints);
>
> breakpoints->breakpoints = new_breakpoints;
> }
Applied to my trivial-patches branch.
Thanks,
Laurent
prev parent reply other threads:[~2022-09-29 19:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-23 9:04 [PATCH] Drop superfluous conditionals around g_free() Markus Armbruster
2022-09-23 9:27 ` Philippe Mathieu-Daudé via
2022-09-29 19:28 ` Laurent Vivier [this message]
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=cbc7643d-40e3-a083-828a-2fafd79f34d2@vivier.eu \
--to=laurent@vivier.eu \
--cc=armbru@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pavel.dovgaluk@ispras.ru \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=sunilmut@microsoft.com \
/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 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).