diff options
author | Jeff Layton <jlayton@redhat.com> | 2007-09-27 06:53:48 -0400 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2007-09-28 11:39:56 +1000 |
commit | 1cecd88106230fc9a8c3527bcdf4195150e9ad64 (patch) | |
tree | 3bd39cfe875943d46319c045d7de9373c5c5f1a4 /support/export/client.c | |
parent | 1992a667c49cdd83ff7d7414a07225fcf34f0ad2 (diff) | |
download | nfs-utils-1cecd88106230fc9a8c3527bcdf4195150e9ad64.tar.gz nfs-utils-1cecd88106230fc9a8c3527bcdf4195150e9ad64.tar.xz nfs-utils-1cecd88106230fc9a8c3527bcdf4195150e9ad64.zip |
rpc.mountd: Change nfs_client->m_hostname to be a dynamically-allocated string
Change nfs_client->m_hostname to be dynamically allocated rather than a
fixed length array of size NFSCLNT_IDMAX. This also adds a bit of
micro-optimization in a few places since it reduces the amount of string
copying that needs to be done.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Steve Dickson <steved@redhat.com>
Signed-off-by: Neil Brown <neilb@suse.de>
Diffstat (limited to 'support/export/client.c')
-rw-r--r-- | support/export/client.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/support/export/client.c b/support/export/client.c index 19b53aa..1754aa0 100644 --- a/support/export/client.c +++ b/support/export/client.c @@ -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); } } |