vfs:glusterfs: preallocate result for glfs_realpath
authorMichael Adam <obnox@samba.org>
Thu, 20 Oct 2016 22:15:06 +0000 (00:15 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 21 Oct 2016 22:28:41 +0000 (00:28 +0200)
This makes us independent of the allocation
method used inside glfs_realpath.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Ira Cooper <ira@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Oct 22 00:28:41 CEST 2016 on sn-devel-144

source3/modules/vfs_glusterfs.c

index 3e15ce6ff98ee6572c32ec0c2d5a9ed1755d920e..1c9be2d97f1eb74f2f07adeca5b4f03b41537017 100644 (file)
@@ -1140,7 +1140,20 @@ static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
 static char *vfs_gluster_realpath(struct vfs_handle_struct *handle,
                                  const char *path)
 {
-       return glfs_realpath(handle->data, path, 0);
+       char *result = NULL;
+       char *resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
+
+       if (resolved_path == NULL) {
+               errno = ENOMEM;
+               return NULL;
+       }
+
+       result = glfs_realpath(handle->data, path, resolved_path);
+       if (result == NULL) {
+               SAFE_FREE(resolved_path);
+       }
+
+       return result;
 }
 
 static bool vfs_gluster_lock(struct vfs_handle_struct *handle,