|
@@ -130,10 +130,11 @@ static int file_close (PAL_HANDLE handle)
|
|
|
|
|
|
int ret = INLINE_SYSCALL(close, 1, fd);
|
|
|
|
|
|
+ /* initial realpath is part of handle object and will be freed with it */
|
|
|
if (handle->file.realpath &&
|
|
|
- handle->file.realpath != (void *) handle + HANDLE_SIZE(file))
|
|
|
+ handle->file.realpath != (void *) handle + HANDLE_SIZE(file)) {
|
|
|
free((void *) handle->file.realpath);
|
|
|
-
|
|
|
+ }
|
|
|
return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : 0;
|
|
|
}
|
|
|
|
|
@@ -270,12 +271,23 @@ static int file_attrsetbyhdl (PAL_HANDLE handle,
|
|
|
static int file_rename (PAL_HANDLE handle, const char * type,
|
|
|
const char * uri)
|
|
|
{
|
|
|
- int ret = INLINE_SYSCALL(rename, 2, handle->file.realpath, uri);
|
|
|
+ char* tmp = strdup(uri);
|
|
|
+ if (!tmp)
|
|
|
+ return -PAL_ERROR_NOMEM;
|
|
|
|
|
|
- if (IS_ERR(ret))
|
|
|
+ int ret = INLINE_SYSCALL(rename, 2, handle->file.realpath, uri);
|
|
|
+ if (IS_ERR(ret)) {
|
|
|
+ free(tmp);
|
|
|
return unix_to_pal_error(ERRNO(ret));
|
|
|
+ }
|
|
|
+
|
|
|
+ /* initial realpath is part of handle object and will be freed with it */
|
|
|
+ if (handle->file.realpath &&
|
|
|
+ handle->file.realpath != (void *) handle + HANDLE_SIZE(file)) {
|
|
|
+ free((void *) handle->file.realpath);
|
|
|
+ }
|
|
|
|
|
|
- handle->file.realpath = malloc_copy(uri, strlen(uri));
|
|
|
+ handle->file.realpath = tmp;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -459,9 +471,11 @@ static int dir_close (PAL_HANDLE handle)
|
|
|
handle->dir.buf = handle->dir.ptr = handle->dir.end = NULL;
|
|
|
}
|
|
|
|
|
|
+ /* initial realpath is part of handle object and will be freed with it */
|
|
|
if (handle->dir.realpath &&
|
|
|
- handle->dir.realpath != (void *) handle + HANDLE_SIZE(dir))
|
|
|
+ handle->dir.realpath != (void *) handle + HANDLE_SIZE(dir)) {
|
|
|
free((void *) handle->dir.realpath);
|
|
|
+ }
|
|
|
|
|
|
if (IS_ERR(ret))
|
|
|
return -PAL_ERROR_BADHANDLE;
|
|
@@ -489,12 +503,23 @@ static int dir_delete (PAL_HANDLE handle, int access)
|
|
|
static int dir_rename (PAL_HANDLE handle, const char * type,
|
|
|
const char * uri)
|
|
|
{
|
|
|
- int ret = INLINE_SYSCALL(rename, 2, handle->dir.realpath, uri);
|
|
|
+ char* tmp = strdup(uri);
|
|
|
+ if (!tmp)
|
|
|
+ return -PAL_ERROR_NOMEM;
|
|
|
|
|
|
- if (IS_ERR(ret))
|
|
|
+ int ret = INLINE_SYSCALL(rename, 2, handle->dir.realpath, uri);
|
|
|
+ if (IS_ERR(ret)) {
|
|
|
+ free(tmp);
|
|
|
return unix_to_pal_error(ERRNO(ret));
|
|
|
+ }
|
|
|
+
|
|
|
+ /* initial realpath is part of handle object and will be freed with it */
|
|
|
+ if (handle->dir.realpath &&
|
|
|
+ handle->dir.realpath != (void *) handle + HANDLE_SIZE(dir)) {
|
|
|
+ free((void *) handle->dir.realpath);
|
|
|
+ }
|
|
|
|
|
|
- handle->dir.realpath = malloc_copy(uri, strlen(uri));
|
|
|
+ handle->dir.realpath = tmp;
|
|
|
return 0;
|
|
|
}
|
|
|
|