]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/export/client.c
rpc.mountd: make exportent->e_hostname a dynamically-allocated string
[nfs-utils.git] / support / export / client.c
index 33dfdb004efac38fa08269906abbf4b045351d45..1754aa0d0d630f25962c3a4abd89bab9a118e7cc 100644 (file)
@@ -118,6 +118,7 @@ client_dup(nfs_client *clp, struct hostent *hp)
        new = (nfs_client *) xmalloc(sizeof(*new));
        memcpy(new, clp, sizeof(*new));
        new->m_type = MCL_FQDN;
+       new->m_hostname = NULL;
 
        client_init(new, (char *) hp->h_name, hp);
        client_add(new);
@@ -127,14 +128,11 @@ client_dup(nfs_client *clp, struct hostent *hp)
 static void
 client_init(nfs_client *clp, const char *hname, struct hostent *hp)
 {
-       if (hp) {
-               strncpy(clp->m_hostname, hp->h_name,
-                       sizeof (clp->m_hostname) -  1);
-       } else {
-               strncpy(clp->m_hostname, hname,
-                       sizeof (clp->m_hostname) - 1);
-       }
-       clp->m_hostname[sizeof (clp->m_hostname) - 1] = '\0';
+       xfree(clp->m_hostname);
+       if (hp)
+               clp->m_hostname = xstrdup(hp->h_name);
+       else
+               clp->m_hostname = xstrdup(hname);
 
        clp->m_exported = 0;
        clp->m_count = 0;
@@ -207,6 +205,7 @@ client_freeall(void)
                head = clientlist + i;
                while (*head) {
                        *head = (clp = *head)->m_next;
+                       xfree(clp->m_hostname);
                        xfree(clp);
                }
        }
@@ -262,6 +261,7 @@ client_compose(struct in_addr addr)
                        name = add_name(name, clp->m_hostname);
                }
        }
+       free(he);
        return name;
 }
 
@@ -329,6 +329,7 @@ add_name(char *old, char *add)
                strcat(new, ",");
                strcat(new, cp);
        }
+       free(old);
        return new;
 }