]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
netapp-nvme: fix ontapdevices segfault in json output
authorMartin George <marting@netapp.com>
Mon, 14 Feb 2022 18:54:07 +0000 (00:24 +0530)
committerMartin George <marting@netapp.com>
Mon, 14 Feb 2022 18:54:07 +0000 (00:24 +0530)
After the upgrade to libnvme, the NetApp plugin for ontapdevices
now 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
ontapdevices. Include a couple of minor changes here as well -
add a newline to the end of the json output, and then free the
json root device.

Signed-off-by: Martin George <marting@netapp.com>
plugins/netapp/netapp-nvme.c

index 7b8b4177c0bbe8fdb43ea49c29fbaa23e7ef5884..e14a970b2922db964a0ff5c27ebe7fec356ab74a 100644 (file)
@@ -334,7 +334,7 @@ static void netapp_ontapdevices_print(struct ontapdevice_info *devices,
        } 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++) {
@@ -357,6 +357,8 @@ static void netapp_ontapdevices_print(struct ontapdevice_info *devices,
                /* complete the json output */
                json_object_add_value_array(root, "ONTAPdevices", json_devices);
                json_print_object(root, NULL);
+               printf("\n");
+               json_free_object(root);
        }
 }