[libvirt] [PATCH 00/17] Refactor virt-login-shell and nss module

Michal Privoznik mprivozn at redhat.com
Wed Aug 7 10:39:13 UTC 2019


On 8/1/19 5:00 PM, Daniel P. Berrangé wrote:
 >
 >

Very nice cleanup, which also makes NSS library smaller in size (I mean 
those .so.2 files).

I've found some mem leaks and mis-alignments, though. Please squash this 
into respective patches:

diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index a9814cf0dc..7122065b28 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -527,7 +527,7 @@ aiforaf(const char *name, int af, struct addrinfo 
*pai, struct addrinfo **aip)

          (*aip)->ai_next = res0;
          while ((*aip)->ai_next)
-           *aip = (*aip)->ai_next;
+            *aip = (*aip)->ai_next;

          addrList++;
      }
diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c
index ddd50288d2..48a54d5841 100644
--- a/tools/nss/libvirt_nss_leases.c
+++ b/tools/nss/libvirt_nss_leases.c
@@ -108,7 +108,7 @@ appendAddr(const char *name ATTRIBUTE_UNUSED,
          return 0;
      }

-     if (af != AF_UNSPEC && af != family) {
+    if (af != AF_UNSPEC && af != family) {
          DEBUG("Skipping address which family is %d, %d requested", 
family, af);
          return 0;
      }
@@ -374,7 +374,7 @@ findLeases(const char *file,
          .addrs = addrs,
          .naddrs = naddrs,
      };
-    yajl_handle parser;
+    yajl_handle parser = NULL;
      char line[1024];
      int rv;

@@ -419,6 +419,7 @@ findLeases(const char *file,
          *addrs = NULL;
          *naddrs = 0;
      }
+    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 9fe5b83e86..fb5526bd7b 100644
--- a/tools/nss/libvirt_nss_macs.c
+++ b/tools/nss/libvirt_nss_macs.c
@@ -55,8 +55,8 @@ typedef struct {

  static int
  findMACsParserString(void *ctx,
-                    const unsigned char *stringVal,
-                    size_t stringLen)
+                     const unsigned char *stringVal,
+                     size_t stringLen)
  {
      findMACsParser *parser = ctx;

@@ -70,6 +70,7 @@ findMACsParserString(void *ctx,
          if (STRNEQ(parser->key, "domain"))
              return 0;

+        free(parser->entry.name);
          if (!(parser->entry.name = strndup((char *)stringVal, stringLen)))
              return 0;
      } else if (parser->state == FIND_MACS_STATE_ENTRY_MACS) {
@@ -93,8 +94,8 @@ findMACsParserString(void *ctx,

  static int
  findMACsParserMapKey(void *ctx,
-                    const unsigned char *stringVal,
-                    size_t stringLen)
+                     const unsigned char *stringVal,
+                     size_t stringLen)
  {
      findMACsParser *parser = ctx;

@@ -226,7 +227,7 @@ findMACs(const char *file,
          .macs = macs,
          .nmacs = nmacs,
      };
-    yajl_handle parser;
+    yajl_handle parser = NULL;
      char line[1024];
      size_t i;
      int rv;
@@ -276,6 +277,7 @@ findMACs(const char *file,
          *macs = NULL;
          *nmacs = 0;
      }
+    yajl_free(parser);
      for (i = 0; i < parserState.entry.nmacs; i++)
          free(parserState.entry.macs[i]);
      free(parserState.entry.macs);



With that:

Reviewed-by: Michal Privoznik <mprivozn at redhat.com>

Michal




More information about the libvir-list mailing list