diff --git a/src/util/virjson.c b/src/util/virjson.c index 4a95e84f5b..18a4585e7b 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1462,6 +1462,11 @@ virJSONValueFromString(const char *jsonstring) VIR_DEBUG("string=%s", jsonstring); tok = json_tokener_new(); + if (!tok) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to create JSON tokener")); + return NULL; + } json_tokener_set_flags(tok, jsonflags); jobj = json_tokener_parse_ex(tok, jsonstring, strlen(jsonstring)); jerr = json_tokener_get_error(tok); @@ -1475,7 +1480,8 @@ virJSONValueFromString(const char *jsonstring) cleanup: json_object_put(jobj); - json_tokener_free(tok); + if (tok) + json_tokener_free(tok); return ret; } diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c index 01e965c4a1..aea81bb56e 100644 --- a/tools/nss/libvirt_nss_leases.c +++ b/tools/nss/libvirt_nss_leases.c @@ -272,6 +272,10 @@ findLeases(const char *file, } tok = json_tokener_new(); + if (!tok) { + ERROR("failed to create JSON tokener"); + goto cleanup; + } json_tokener_set_flags(tok, jsonflags); do { @@ -301,7 +305,8 @@ findLeases(const char *file, cleanup: json_object_put(jobj); - json_tokener_free(tok); + if (tok) + json_tokener_free(tok); if (ret != 0) { free(*addrs); *addrs = NULL; diff --git a/tools/nss/libvirt_nss_macs.c b/tools/nss/libvirt_nss_macs.c index 430023abec..23229a18f3 100644 --- a/tools/nss/libvirt_nss_macs.c +++ b/tools/nss/libvirt_nss_macs.c @@ -134,6 +134,10 @@ findMACs(const char *file, } tok = json_tokener_new(); + if (!tok) { + ERROR("failed to create JSON tokener"); + goto cleanup; + } json_tokener_set_flags(tok, jsonflags); do { @@ -162,7 +166,8 @@ findMACs(const char *file, cleanup: json_object_put(jobj); - json_tokener_free(tok); + if (tok) + json_tokener_free(tok); if (ret != 0) { for (i = 0; i < *nmacs; i++) { char *mac = (*macs)[i];