nbd-proxy: Increment refcount in print_metadata()
The json_object.h states that json_object_object_get_ex() does not
increase the reference count:
https://github.com/json-c/json-c/blob/json-c-0.11/json_object.h#L271
With the latest json-c-0.13.1, an assert check was added, so calling
json_object_put() to free an object created with json_object_object_get_ex()
causes an app crash:
root@witherspoon:~# nbd-proxy --metadata
{ "0": { "description": "Virtual media device" } }
nbd-proxy: ../json-c-0.13.1/json_object.c:189: json_object_put: Assertion `jso->_ref_count > 0' failed.
Aborted
Need to increase the refcount in print_metadata() via json_object_get()
so that the json_object_put() there does not free the metadata.
Tested: Verified no error is seeing anymore:
root@witherspoon:/tmp# ./nbd-proxy --metadata
{ "0": { "description": "Virtual media device" } }
Change-Id: Ic48b98813a45f993cf00415243769533b2576cab
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/nbd-proxy.c b/nbd-proxy.c
index 35f0ccd..bffe1f9 100644
--- a/nbd-proxy.c
+++ b/nbd-proxy.c
@@ -586,7 +586,7 @@
for (i = 0; i < ctx->n_configs; i++) {
struct config *config = &ctx->configs[i];
json_object_object_add(md, config->name,
- config->metadata);
+ json_object_get(config->metadata));
}
puts(json_object_get_string(md));