[PATCH 6/9] domain_conf: rewrite virDomainSoundCodecDefFree()

Kristina Hanicova posted 9 patches 3 years, 6 months ago
There is a newer version of this series
[PATCH 6/9] domain_conf: rewrite virDomainSoundCodecDefFree()
Posted by Kristina Hanicova 3 years, 6 months ago
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
---
 src/conf/domain_conf.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f51476c968..88d50d27f5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2955,10 +2955,8 @@ void virDomainSmartcardDefFree(virDomainSmartcardDef *def)
 
 void virDomainSoundCodecDefFree(virDomainSoundCodecDef *def)
 {
-    if (!def)
-        return;
-
-    g_free(def);
+    if (def)
+        g_free(def);
 }
 
 void virDomainSoundDefFree(virDomainSoundDef *def)
-- 
2.35.3
Re: [PATCH 6/9] domain_conf: rewrite virDomainSoundCodecDefFree()
Posted by Daniel P. Berrangé 3 years, 6 months ago
On Wed, Jul 20, 2022 at 03:11:09PM +0200, Kristina Hanicova wrote:
> Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
> ---
>  src/conf/domain_conf.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index f51476c968..88d50d27f5 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -2955,10 +2955,8 @@ void virDomainSmartcardDefFree(virDomainSmartcardDef *def)
>  
>  void virDomainSoundCodecDefFree(virDomainSoundCodecDef *def)
>  {
> -    if (!def)
> -        return;
> -
> -    g_free(def);
> +    if (def)
> +        g_free(def);
>  }

This is not desirable - our default pattern for Free() funcs is
to return immediately if NULL. At a later date other statements
may end up being added in the middle of this existing function,
which would involve then reverting this proposed change.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|