nvdimm acpi: fix g_array_free() with NULL pointer
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
@@ -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
Quoted 16 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' failedCc Xiao Guangrong <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/acpi/nvdimm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/acpi/nvdimm.c +0
-0
hw/acpi/nvdimm.c static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf) · line 380
Quoted 7 lines
hw/acpi/nvdimm.c +3
-1@@ -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); + }
Er, i do not know why it is NULL as we have init-ed it in nvdimm_init_fit_buffer:
static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf)
{
fit_buf->fit = g_array_new(false, true /* clear */, 1);
}And i can not reproduce it on my box, could you share your command line and the based commit id?
Thanks!
Stefan Hajnoczi
NAKQuoted 6 lines · Xiao Guangrong
Quoted 3 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:
Quoted 7 lines
Quoted 7 lines
GLib-CRITICAL **:
g_array_free: assertion 'array' failedCc Xiao Guangrong <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/acpi/nvdimm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
NACK
Quoted 16 lines
hw/acpi/nvdimm.c static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf) · line 380
Quoted 13 lines
hw/acpi/nvdimm.c +3
-1@@ -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); + }Er, i do not know why it is NULL as we have init-ed it in
nvdimm_init_fit_buffer:
Quoted 7 lines
static void
nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf){ fit_buf->fit = g_array_new(false, true /* clear */, 1); }And i can not reproduce it on my box, could you share your command line and the based commit id?
Good point, it happens when nvdimm_plug() is called but -M pc,nvdimm is missing from the command-line. This means nvdimm_init_acpi_state() was not called by pc_init1():
$ x86_64-softmmu/qemu-system-x86_64 \
-enable-kvm \
-m 1G,slots=2,maxmem=16G \
-drive if=virtio,file=test.img,format=raw \
-object memory-backend-file,id=hostmem0,mem-path=mydimm,share=on,size=8G \
-device nvdimm,id=nvdimm0,memdev=hostmem0Do you want to audit the code to check if anything else misbehaves when -device nvdimm is used without -M pc,nvdimm?
Stefan
CCed Haozhong
Quoted 52 lines · Stefan Hajnoczi
Quoted 6 lines · Xiao Guangrong
Quoted 3 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:Quoted 7 lines
Quoted 7 lines
GLib-CRITICAL **:
g_array_free: assertion 'array' failedCc Xiao Guangrong <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/acpi/nvdimm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)NACK
Quoted 16 lines
hw/acpi/nvdimm.c static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf) · line 380
Quoted 13 lines
hw/acpi/nvdimm.c +3
-1@@ -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); + }Er, i do not know why it is NULL as we have init-ed it in
nvdimm_init_fit_buffer:Quoted 7 lines
static void
nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf){ fit_buf->fit = g_array_new(false, true /* clear */, 1); }And i can not reproduce it on my box, could you share your command line and the based commit id?
Good point, it happens when
nvdimm_plug()is called but -M pc,nvdimm is missing from the command-line. This meansnvdimm_init_acpi_state()was not called bypc_init1():$ x86_64-softmmu/qemu-system-x86_64 \ -enable-kvm \ -m 1G,slots=2,maxmem=16G \ -drive if=virtio,file=test.img,format=raw \ -object memory-backend-file,id=hostmem0,mem-path=mydimm,share=on,size=8G \ -device nvdimm,id=nvdimm0,memdev=hostmem0
Quoted 2 lines
Do you want to audit the code to check if anything else misbehaves when -device nvdimm is used without -M pc,nvdimm?
Yes. Haozhong will help me to audit the code and fix this crash.
Thanks for your report, Stefan!