Drop superfluous conditionals around g_free()
PATCH 1/1 Drop superfluous conditionals around g_free()
There is no need to guard g_free(P) with if (P): g_free(NULL) is safe.
Signed-off-by Markus Armbruster <[email protected]>
--- replay/replay.c | 6 ++---- target/i386/kvm/kvm.c | 12 ++++-------- target/i386/whpx/whpx-all.c | 14 ++++++-------- 3 files changed, 12 insertions(+), 20 deletions(-)
replay/replay.c +2 -4
@@ -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 ;
target/i386/kvm/kvm.c +4 -8
@@ -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);
target/i386/whpx/whpx-all.c +6 -8
@@ -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; }
Signature · 1 line
2.37.2
Quoted 9 lines · Markus Armbruster
There is no need to guard
g_free(P)with if (P):g_free(NULL)is safe.Signed-off-by Markus Armbruster <[email protected]>--- replay/replay.c | 6 ++---- target/i386/kvm/kvm.c | 12 ++++-------- target/i386/whpx/whpx-all.c | 14 ++++++-------- 3 files changed, 12 insertions(+), 20 deletions(-)
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Laurent Vivier
AppliedLe 23/09/2022 à 11:04, Markus Armbruster a écrit :
Quoted 65 lines
There is no need to guard
g_free(P)with if (P):g_free(NULL)is safe.Signed-off-by Markus Armbruster <[email protected]>--- replay/replay.c | 6 ++---- target/i386/kvm/kvm.c | 12 ++++-------- target/i386/whpx/whpx-all.c | 14 ++++++-------- 3 files changed, 12 insertions(+), 20 deletions(-)replay/replay.c +2
-4@@ -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 ;target/i386/kvm/kvm.c +4
-8@@ -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);target/i386/whpx/whpx-all.c +0
-7@@ -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);
target/i386/whpx/whpx-all.c static void whpx_translate_cpu_breakpoints( · line 1236
Quoted 10 lines
target/i386/whpx/whpx-all.c +6
-1- } +/* +* 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