From 9d4a44f0b8353859b43f126ee65b013af22d6819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Mon, 17 May 2021 20:34:04 +0200 Subject: [PATCH] linux/libshare: nfs: don't needlessly strdup() hostspec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Don Brady Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Signed-off-by: Ahelenia ZiemiaƄska Closes #12067 --- lib/libshare/os/linux/nfs.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/libshare/os/linux/nfs.c b/lib/libshare/os/linux/nfs.c index d66228336d..d6dbc158ce 100644 --- a/lib/libshare/os/linux/nfs.c +++ b/lib/libshare/os/linux/nfs.c @@ -247,8 +247,8 @@ foreach_nfs_host(sa_share_impl_t impl_share, FILE *tmpfile, /* * Converts a Solaris NFS host specification to its Linux equivalent. */ -static int -get_linux_hostspec(const char *solaris_hostspec, char **plinux_hostspec) +static const char * +get_linux_hostspec(const char *solaris_hostspec) { /* * For now we just support CIDR masks (e.g. @192.168.0.0/16) and host @@ -259,16 +259,10 @@ get_linux_hostspec(const char *solaris_hostspec, char **plinux_hostspec) * Solaris host specifier, e.g. @192.168.0.0/16; we just need * to skip the @ in this case */ - *plinux_hostspec = strdup(solaris_hostspec + 1); + return (solaris_hostspec + 1); } else { - *plinux_hostspec = strdup(solaris_hostspec); + return (solaris_hostspec); } - - if (*plinux_hostspec == NULL) { - return (SA_NO_MEMORY); - } - - return (SA_OK); } /* @@ -397,25 +391,18 @@ nfs_add_entry(FILE *tmpfile, const char *sharepath, const char *host, const char *security, const char *access_opts, void *pcookie) { - int error; - char *linuxhost; const char *linux_opts = (const char *)pcookie; - error = get_linux_hostspec(host, &linuxhost); - if (error != SA_OK) - return (error); - if (linux_opts == NULL) linux_opts = ""; - if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", sharepath, linuxhost, - security, access_opts, linux_opts) < 0) { + if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", sharepath, + get_linux_hostspec(host), security, access_opts, + linux_opts) < 0) { fprintf(stderr, "failed to write to temporary file\n"); - free(linuxhost); return (SA_SYSTEM_ERR); } - free(linuxhost); return (SA_OK); }