Skip to contentSkip to conversation

smbios: use g_free directly on NULL pointers

PATCH Applied Paolo Bonzini 3 participants 3 messages Jun 4, 2014 – Jun 8, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smbios: use g_free directly on NULL pointers

No need to wrap it with an if.

---
 hw/i386/smbios.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
hw/i386/smbios.c +2 -7
index 7660718..ab89420 100644
@@ -740,11 +740,6 @@ void smbios_set_cpuid(uint32_t version, uint32_t features)
         field = value;                                                    \
     }
 
-#define G_FREE_UNLESS_NULL(ptr)                                           \
-    if (ptr != NULL) {                                                    \
-        g_free(ptr);                                                      \
-    }
-
 void smbios_set_defaults(const char *manufacturer, const char *product,
                          const char *version, bool legacy_mode)
 {
@@ -753,7 +748,7 @@ void smbios_set_defaults(const char *manufacturer, const char *product,
 
     /* drop unwanted version of command-line file blob(s) */
     if (smbios_legacy) {
-        G_FREE_UNLESS_NULL(smbios_tables);
+        g_free(smbios_tables);
         /* in legacy mode, also complain if fields were given for types > 1 */
         if (find_next_bit(have_fields_bitmap,
                           SMBIOS_MAX_TYPE+1, 2) < SMBIOS_MAX_TYPE+1) {
@@ -762,7 +757,7 @@ void smbios_set_defaults(const char *manufacturer, const char *product,
             exit(1);
         }
     } else {
-        G_FREE_UNLESS_NULL(smbios_entries);
+        g_free(smbios_entries);
     }
 
     SMBIOS_SET_DEFAULT(type1.manufacturer, manufacturer);
Signature · 1 line
1.8.3.1
Reviewed-by Benoit Canet on v1 1/1
#1 lore raw
Quoted 45 lines · Paolo Bonzini

No need to wrap it with an if.

---
 hw/i386/smbios.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
hw/i386/smbios.c +2 -7
index 7660718..ab89420 100644
@@ -740,11 +740,6 @@ void smbios_set_cpuid(uint32_t version, uint32_t features)
         field = value;                                                    \
     }
 
-#define G_FREE_UNLESS_NULL(ptr)                                           \
-    if (ptr != NULL) {                                                    \
-        g_free(ptr);                                                      \
-    }
-
 void smbios_set_defaults(const char *manufacturer, const char *product,
                          const char *version, bool legacy_mode)
 {
@@ -753,7 +748,7 @@ void smbios_set_defaults(const char *manufacturer, const char *product,
 
     /* drop unwanted version of command-line file blob(s) */
     if (smbios_legacy) {
-        G_FREE_UNLESS_NULL(smbios_tables);
+        g_free(smbios_tables);
         /* in legacy mode, also complain if fields were given for types > 1 */
         if (find_next_bit(have_fields_bitmap,
                           SMBIOS_MAX_TYPE+1, 2) < SMBIOS_MAX_TYPE+1) {
@@ -762,7 +757,7 @@ void smbios_set_defaults(const char *manufacturer, const char *product,
             exit(1);
         }
     } else {
-        G_FREE_UNLESS_NULL(smbios_entries);
+        g_free(smbios_entries);
     }
 
     SMBIOS_SET_DEFAULT(type1.manufacturer, manufacturer);
Signature · 1 line
1.8.3.1