s3: VFS: Fix memory leak in vfs_ceph.
authorVandana Rungta <vrungta@amazon.com>
Tue, 8 May 2018 18:27:47 +0000 (11:27 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 9 May 2018 02:28:11 +0000 (04:28 +0200)
Centralize error handling.

https://bugzilla.samba.org/show_bug.cgi?id=13424

Signed-off-by: Vandana Rungta <vrungta@amazon.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed May  9 04:28:11 CEST 2018 on sn-devel-144

source3/modules/vfs_ceph.c

index e49e7a6be00fa97517e69a5135b6a464f070c8f1..87df83e805bf27be34eb42bb1a82af525428bcf2 100644 (file)
@@ -1211,30 +1211,31 @@ static struct smb_filename *cephwrap_realpath(struct vfs_handle_struct *handle,
                                TALLOC_CTX *ctx,
                                const struct smb_filename *smb_fname)
 {
-       char *result;
+       char *result = NULL;
        const char *path = smb_fname->base_name;
        size_t len = strlen(path);
        struct smb_filename *result_fname = NULL;
+       int r = -1;
 
-       result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
        if (len && (path[0] == '/')) {
-               int r = asprintf(&result, "%s", path);
-               if (r < 0) return NULL;
+               r = asprintf(&result, "%s", path);
        } else if ((len >= 2) && (path[0] == '.') && (path[1] == '/')) {
                if (len == 2) {
-                       int r = asprintf(&result, "%s",
+                       r = asprintf(&result, "%s",
                                        handle->conn->connectpath);
-                       if (r < 0) return NULL;
                } else {
-                       int r = asprintf(&result, "%s/%s",
+                       r = asprintf(&result, "%s/%s",
                                        handle->conn->connectpath, &path[2]);
-                       if (r < 0) return NULL;
                }
        } else {
-               int r = asprintf(&result, "%s/%s",
+               r = asprintf(&result, "%s/%s",
                                handle->conn->connectpath, path);
-               if (r < 0) return NULL;
        }
+
+       if (r < 0) {
+               return NULL;
+       }
+
        DBG_DEBUG("[CEPH] realpath(%p, %s) = %s\n", handle, path, result);
        result_fname = synthetic_smb_fname(ctx,
                                result,