From ff9597d28d957b18639b0e93f45440e13b71687a Mon Sep 17 00:00:00 2001 From: Martin George Date: Fri, 18 Mar 2022 13:51:06 +0530 Subject: [PATCH] netapp-nvme: fix smdevices segfault in json output After the upgrade to libnvme, the NetApp plugin for smdevices segfaults due to the wrong json object type as shown below: nvme: json_object.c:1194: json_object_array_add: Assertion `json_object_get_type(jso) == json_type_array' failed. Aborted (core dumped) Fix this by passing the appropriate json array type for smdevices. Also include a couple of minor changes as well - add a newline to the end of the json output, and then free the json root device. Signed-off-by: Martin George Tested-by: Clayton Skaggs --- plugins/netapp/netapp-nvme.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index fa8943bd..96304427 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -258,7 +258,7 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int else if (format == NJSON) { /* prepare for json output */ root = json_create_object(); - json_devices = json_create_object(); + json_devices = json_create_array(); } for (i = 0; i < count; i++) { @@ -290,6 +290,8 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int /* complete the json output */ json_object_add_value_array(root, "SMdevices", json_devices); json_print_object(root, NULL); + printf("\n"); + json_free_object(root); } } -- 2.50.1