Re: [PATCH 3/3] nss: Don't leak memory on parse error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/9/19 11:04 AM, Daniel P. Berrangé wrote:
On Fri, Aug 09, 2019 at 10:49:11AM +0200, Michal Privoznik wrote:
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 <mprivozn@xxxxxxxxxx>
---
  tools/nss/libvirt_nss_leases.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 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;
          }
      }

Same fix needed in libvirt_nss_macs.c too

Ah, good point. I completely forgot about libvirt_nss_macs.c; The problem I'm fixing in 1/3 applies there too. I'm squashing in the obvious fix (even though macs JSON doesn't have any unexpected keys yet).

Thanks,
Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux