Unfortunately, yajl_free() is not NOP on NULL. It really does
expect a valid pointer. Therefore, check whether the pointer we
want to pass to it is NULL or not.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/util/virjson.c | 2 +-
tools/nss/libvirt_nss_leases.c | 3 ++-
tools/nss/libvirt_nss_macs.c | 3 ++-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/util/virjson.c b/src/util/virjson.c
index be472d49e4..dc662bf8e9 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1838,7 +1838,7 @@ virJSONValueFromString(const char *jsonstring)
if (!hand) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to create JSON parser"));
- goto cleanup;
+ return NULL;
}
/* Yajl 2 is nice enough to default to rejecting trailing garbage. */
diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c
index 7c431e4d53..015bbc4ab6 100644
--- a/tools/nss/libvirt_nss_leases.c
+++ b/tools/nss/libvirt_nss_leases.c
@@ -426,7 +426,8 @@ findLeases(const char *file,
*addrs = NULL;
*naddrs = 0;
}
- yajl_free(parser);
+ if (parser)
+ yajl_free(parser);
free(parserState.entry.ipaddr);
free(parserState.entry.macaddr);
free(parserState.entry.hostname);
diff --git a/tools/nss/libvirt_nss_macs.c b/tools/nss/libvirt_nss_macs.c
index 05d096a348..d4b165eef6 100644
--- a/tools/nss/libvirt_nss_macs.c
+++ b/tools/nss/libvirt_nss_macs.c
@@ -278,7 +278,8 @@ findMACs(const char *file,
*macs = NULL;
*nmacs = 0;
}
- yajl_free(parser);
+ if (parser)
+ yajl_free(parser);
for (i = 0; i < parserState.entry.nmacs; i++)
free(parserState.entry.macs[i]);
free(parserState.entry.macs);
--
2.24.1