Commit 09775b17 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

file: initialize access_t after the open operation is succesful

parent 30057956
...@@ -132,24 +132,11 @@ static bool IsRemote (int fd) ...@@ -132,24 +132,11 @@ static bool IsRemote (int fd)
int Open( vlc_object_t *p_this ) int Open( vlc_object_t *p_this )
{ {
access_t *p_access = (access_t*)p_this; access_t *p_access = (access_t*)p_this;
access_sys_t *p_sys = malloc (sizeof (*p_sys));
const char *path = p_access->psz_path; const char *path = p_access->psz_path;
#ifdef WIN32 #ifdef WIN32
bool is_remote = false; bool is_remote = false;
#endif #endif
if (unlikely(p_sys == NULL))
return VLC_ENOMEM;
access_InitFields (p_access);
p_access->pf_read = FileRead;
p_access->pf_block = NULL;
p_access->pf_control = FileControl;
p_access->pf_seek = FileSeek;
p_access->p_sys = p_sys;
p_sys->i_nb_reads = 0;
p_sys->b_pace_control = true;
/* Open file */ /* Open file */
int fd = -1; int fd = -1;
...@@ -178,11 +165,9 @@ int Open( vlc_object_t *p_this ) ...@@ -178,11 +165,9 @@ int Open( vlc_object_t *p_this )
#endif #endif
} }
if (fd == -1) if (fd == -1)
goto error; return VLC_EGENERIC;
#ifdef HAVE_SYS_STAT_H
struct stat st; struct stat st;
if (fstat (fd, &st)) if (fstat (fd, &st))
{ {
msg_Err (p_access, "failed to read (%m)"); msg_Err (p_access, "failed to read (%m)");
...@@ -195,6 +180,23 @@ int Open( vlc_object_t *p_this ) ...@@ -195,6 +180,23 @@ int Open( vlc_object_t *p_this )
msg_Dbg (p_access, "ignoring directory"); msg_Dbg (p_access, "ignoring directory");
goto error; goto error;
} }
access_sys_t *p_sys = malloc (sizeof (*p_sys));
if (unlikely(p_sys == NULL))
goto error;
access_InitFields (p_access);
p_access->pf_read = FileRead;
p_access->pf_block = NULL;
p_access->pf_control = FileControl;
p_access->pf_seek = FileSeek;
p_access->p_sys = p_sys;
p_sys->i_nb_reads = 0;
p_sys->fd = fd;
p_sys->caching = var_CreateGetInteger (p_access, "file-caching");
if (IsRemote(fd))
p_sys->caching += var_CreateGetInteger (p_access, "network-caching");
p_sys->b_pace_control = true;
if (S_ISREG (st.st_mode)) if (S_ISREG (st.st_mode))
p_access->info.i_size = st.st_size; p_access->info.i_size = st.st_size;
else if (!S_ISBLK (st.st_mode)) else if (!S_ISBLK (st.st_mode))
...@@ -202,15 +204,6 @@ int Open( vlc_object_t *p_this ) ...@@ -202,15 +204,6 @@ int Open( vlc_object_t *p_this )
p_access->pf_seek = NoSeek; p_access->pf_seek = NoSeek;
p_sys->b_pace_control = strcasecmp (p_access->psz_access, "stream"); p_sys->b_pace_control = strcasecmp (p_access->psz_access, "stream");
} }
#else
# warning File size not known!
#endif
p_sys->caching = var_CreateGetInteger (p_access, "file-caching");
if (IsRemote(fd))
p_sys->caching += var_CreateGetInteger (p_access, "network-caching");
p_sys->fd = fd;
if (p_access->pf_seek != NoSeek) if (p_access->pf_seek != NoSeek)
{ {
...@@ -232,9 +225,7 @@ int Open( vlc_object_t *p_this ) ...@@ -232,9 +225,7 @@ int Open( vlc_object_t *p_this )
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
if (fd != -1) close (fd);
close (fd);
free (p_sys);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment