nfs_strerror() leaks memory allocated by xasprintf(), which never gets
free()'d. Replace it with nfs_error_msg(), which handles this internally.

function                                             old     new   delta
nfs_error_msg                                          -      81     +81
nfs_err_stat                                          18      19      +1
.rodata                                           429340  429328     -12
nfsmount                                            3893    3875     -18
nfs_strerror                                          52       -     -52
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/2 up/down: 82/-82)              Total: 0 bytes

Signed-off-by: Alexander Shishkin <[email protected]>
---
 util-linux/mount.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/util-linux/mount.c b/util-linux/mount.c
index b973179..e7a7e9a 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -749,11 +749,12 @@ enum {
 #ifndef EDQUOT
 # define EDQUOT ENOSPC
 #endif
-/* Convert each NFSERR_BLAH into EBLAH */
+/* Convert each NFSERR_BLAH into EBLAH, null-terminated so that it
+ * can be searched with strchr() */
 static const uint8_t nfs_err_stat[] = {
         1,  2,  5,  6, 13, 17,
        19, 20, 21, 22, 27, 28,
-       30, 63, 66, 69, 70, 71
+       30, 63, 66, 69, 70, 71, 0
 };
 #if ( \
        EPERM | ENOENT      | EIO      | ENXIO | EACCES| EEXIST | \
@@ -768,15 +769,18 @@ static const nfs_err_type nfs_err_errnum[] = {
        ENODEV, ENOTDIR     , EISDIR   , EINVAL, EFBIG , ENOSPC,
        EROFS , ENAMETOOLONG, ENOTEMPTY, EDQUOT, ESTALE, EREMOTE
 };
-static char *nfs_strerror(int status)
+
+static void nfs_error_msg(char *hostname, char *path, unsigned int status)
 {
-       int i;
+       uint8_t *r;
+       char *reason = "unknown nfs status";
 
-       for (i = 0; i < ARRAY_SIZE(nfs_err_stat); i++) {
-               if (nfs_err_stat[i] == status)
-                       return strerror(nfs_err_errnum[i]);
-       }
-       return xasprintf("unknown nfs status return value: %d", status);
+       r = strchr(nfs_err_stat, status);
+       if (r)
+               reason = strerror(nfs_err_errnum[r - nfs_err_stat]);
+
+       bb_error_msg("%s:%s failed, reason given by server: %s (%d)", hostname, 
path,
+                    reason, status);
 }
 
 static bool_t xdr_fhandle(XDR *xdrs, fhandle objp)
@@ -1457,9 +1461,7 @@ static NOINLINE int nfsmount(struct mntent *mp, long 
vfsflags, char *filteropts)
 
        if (nfsvers == 2) {
                if (status.nfsv2.fhs_status != 0) {
-                       bb_error_msg("%s:%s failed, reason given by server: %s",
-                               hostname, pathname,
-                               nfs_strerror(status.nfsv2.fhs_status));
+                       nfs_error_msg(hostname, pathname, 
status.nfsv2.fhs_status);
                        goto fail;
                }
                memcpy(data.root.data,
@@ -1472,9 +1474,7 @@ static NOINLINE int nfsmount(struct mntent *mp, long 
vfsflags, char *filteropts)
        } else {
                fhandle3 *my_fhandle;
                if (status.nfsv3.fhs_status != 0) {
-                       bb_error_msg("%s:%s failed, reason given by server: %s",
-                               hostname, pathname,
-                               nfs_strerror(status.nfsv3.fhs_status));
+                       nfs_error_msg(hostname, pathname, 
status.nfsv3.fhs_status);
                        goto fail;
                }
                my_fhandle = &status.nfsv3.mountres3_u.mountinfo.fhandle;
-- 
1.7.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to