From 0dc84c347a57e828f836643bf8efcc3fea37d38e Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 9 Aug 2019 10:37:05 +0200 Subject: [PATCH] nss: Don't leak memory on parse error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If yajl_parse() fails, we try to print an error message. For that, yajl_get_error() is used. However, its documentation say that caller is also responsible for freeing the memory it allocates by using yajl_free_error(). Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrangé --- tools/nss/libvirt_nss_leases.c | 7 ++++--- tools/nss/libvirt_nss_macs.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c index 577b5a2fd1..977e3415f7 100644 --- a/tools/nss/libvirt_nss_leases.c +++ b/tools/nss/libvirt_nss_leases.c @@ -399,9 +399,10 @@ findLeases(const char *file, if (yajl_parse(parser, (const unsigned char *)line, rv) != yajl_status_ok) { - ERROR("Parse failed %s", - yajl_get_error(parser, 1, - (const unsigned char*)line, rv)); + unsigned char *err = yajl_get_error(parser, 1, + (const unsigned char*)line, rv); + ERROR("Parse failed %s", (const char *) err); + yajl_free_error(parser, err); goto cleanup; } } diff --git a/tools/nss/libvirt_nss_macs.c b/tools/nss/libvirt_nss_macs.c index ef14ef0a24..05d096a348 100644 --- a/tools/nss/libvirt_nss_macs.c +++ b/tools/nss/libvirt_nss_macs.c @@ -252,9 +252,10 @@ findMACs(const char *file, if (yajl_parse(parser, (const unsigned char *)line, rv) != yajl_status_ok) { - ERROR("Parse failed %s", - yajl_get_error(parser, 1, - (const unsigned char*)line, rv)); + unsigned char *err = yajl_get_error(parser, 1, + (const unsigned char*)line, rv); + ERROR("Parse failed %s", (const char *) err); + yajl_free_error(parser, err); goto cleanup; } } -- GitLab