[vlc-commits] plaintext: fix invalid fd in error path (cid #1348117)
Thomas Guillem
git at videolan.org
Thu Jan 14 14:12:17 CET 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jan 14 14:11:08 2016 +0100| [730515581e950a6eee410f45db1f96cf488f3300] | committer: Thomas Guillem
plaintext: fix invalid fd in error path (cid #1348117)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=730515581e950a6eee410f45db1f96cf488f3300
---
modules/keystore/plaintext.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/modules/keystore/plaintext.c b/modules/keystore/plaintext.c
index d2049ff..b8ea30e 100644
--- a/modules/keystore/plaintext.c
+++ b/modules/keystore/plaintext.c
@@ -454,12 +454,13 @@ CleanUp(vlc_keystore_sys *p_sys)
{
if (p_sys->b_error)
{
- if (truncate0(p_sys->i_fd))
+ if (p_sys->i_fd != -1 && truncate0(p_sys->i_fd))
vlc_unlink(p_sys->psz_file);
}
#ifdef HAVE_FLOCK
- flock(p_sys->i_fd, LOCK_UN);
+ if (p_sys->i_fd != -1)
+ flock(p_sys->i_fd, LOCK_UN);
#endif
fclose(p_sys->p_file);
}
@@ -493,14 +494,16 @@ Open(vlc_object_t *p_this)
p_sys->psz_file = psz_file;
p_sys->p_file = vlc_fopen(p_sys->psz_file, "a+");
+ p_sys->i_fd = -1;
if (!p_sys->p_file)
{
CleanUp(p_sys);
return VLC_EGENERIC;
}
- p_sys->i_fd = fileno(p_sys->p_file);
- if (p_sys->i_fd == -1)
+
+ int i_fd = fileno(p_sys->p_file);
+ if (i_fd == -1)
{
CleanUp(p_sys);
return VLC_EGENERIC;
@@ -510,12 +513,13 @@ Open(vlc_object_t *p_this)
* If HAVE_FLOCK is not defined, the running OS is most likely Windows
* and a lock was already acquired when the file was opened. */
#ifdef HAVE_FLOCK
- if (flock(p_sys->i_fd, LOCK_EX|LOCK_NB) != 0)
+ if (flock(i_fd, LOCK_EX|LOCK_NB) != 0)
{
CleanUp(p_sys);
return VLC_EGENERIC;
}
#endif
+ p_sys->i_fd = i_fd;
if (list_read(p_sys, &p_sys->list) != VLC_SUCCESS)
{
More information about the vlc-commits
mailing list