Skip to contentSkip to conversation

nvdimm acpi: fix g_array_free() with NULL pointer

PATCH NAK Stefan Hajnoczi 2 participants 3 messages Jan 11, 2017 – Jan 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvdimm acpi: fix g_array_free() with NULL pointer

Unlike g_free(), g_array_free() does not accept a NULL pointer argument. The following error is logged when an nvdimm device is realized:

GLib-CRITICAL **: g_array_free: assertion 'array' failed

---
 hw/acpi/nvdimm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/acpi/nvdimm.c +3 -1
index 8e7d6ec..8f0a484 100644
@@ -375,7 +375,9 @@ static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf)
 
 static void nvdimm_build_fit_buffer(NvdimmFitBuffer *fit_buf)
 {
-    g_array_free(fit_buf->fit, true);
+    if (fit_buf->fit) {
+        g_array_free(fit_buf->fit, true);
+    }
     fit_buf->fit = nvdimm_build_device_structure();
     fit_buf->dirty = true;
 }
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Wed, 11 Jan 2017 09:44:43 +0000 Stefan Hajnoczi <[email protected]> wrote:

Unlike g_free(), g_array_free() does not accept a NULL pointer argument. The following error is logged when an nvdimm device is realized:

GLib-CRITICAL **: g_array_free: assertion 'array' failed

Quoted 19 lines
---
 hw/acpi/nvdimm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/acpi/nvdimm.c +3 -1
index 8e7d6ec..8f0a484 100644
@@ -375,7 +375,9 @@ static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf)
 
 static void nvdimm_build_fit_buffer(NvdimmFitBuffer *fit_buf)
 {
-    g_array_free(fit_buf->fit, true);
+    if (fit_buf->fit) {
+        g_array_free(fit_buf->fit, true);
+    }
     fit_buf->fit = nvdimm_build_device_structure();
     fit_buf->dirty = true;
 }
author NAK
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 10 lines · Stefan Hajnoczi

Unlike g_free(), g_array_free() does not accept a NULL pointer argument. The following error is logged when an nvdimm device is realized:

GLib-CRITICAL **: g_array_free: assertion 'array' failed

---
 hw/acpi/nvdimm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

NACK

Guangrong pointed out this patch is masking another bug. There seems to be a problem with the order in which functions are called when the device is realized.