Cleaned up clipboard file fd handling

This commit is contained in:
akallabeth 2021-03-26 10:52:35 +01:00 committed by akallabeth
parent 36ffb3a1d4
commit 76047bed25
1 changed files with 6 additions and 15 deletions

View File

@ -95,6 +95,7 @@ error:
free(file);
return NULL;
}
static UINT posix_file_read_close(struct posix_file* file, BOOL force);
static void free_posix_file(void* the_file)
{
@ -103,14 +104,7 @@ static void free_posix_file(void* the_file)
if (!file)
return;
if (file->fd >= 0)
{
if (close(file->fd) < 0)
{
int err = errno;
WLog_WARN(TAG, "failed to close fd %d: %s", file->fd, strerror(err));
}
}
posix_file_read_close(file, TRUE);
free(file->local_name);
free(file->remote_name);
@ -1017,12 +1011,12 @@ error:
return ERROR_READ_FAULT;
}
static UINT posix_file_read_close(struct posix_file* file)
UINT posix_file_read_close(struct posix_file* file, BOOL force)
{
if (file->fd < 0)
return NO_ERROR;
if (file->offset == file->size)
if ((file->offset >= file->size) || force)
{
WLog_VRB(TAG, "close file %d", file->fd);
@ -1057,12 +1051,9 @@ static UINT posix_file_get_range(struct posix_file* file, UINT64 offset, UINT32
if (error)
goto out;
error = posix_file_read_close(file);
if (error)
goto out;
out:
posix_file_read_close(file, FALSE);
return error;
}