Discussion:
[libdvdcss-devel] Properly check for and return errors from close().
Diego Biurrun
2014-11-13 13:56:18 UTC
Permalink
libdvdcss | branch: master | Diego Biurrun <***@biurrun.de> | Wed Nov 12 23:53:41 2014 +0100| [9729f35a0b9991af6b18a1862dc924bf9903e096] | committer: Diego Biurrun

Properly check for and return errors from close().

Also fix a memory leak on close() failure.
http://git.videolan.org/gitweb.cgi/libdvdcss.git/?a=commit;h=9729f35a0b9991af6b18a1862dc924bf9903e096
---

src/device.c | 12 ++++++++----
src/libdvdcss.c | 7 +++----
2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/device.c b/src/device.c
index ddb216e..e824b54 100644
--- a/src/device.c
+++ b/src/device.c
@@ -412,6 +412,7 @@ int dvdcss_raw_open ( dvdcss_t dvdcss, const char *psz_device )

int dvdcss_close_device ( dvdcss_t dvdcss )
{
+ int i_ret;
#if defined( WIN32 )
if( dvdcss->b_file )
{
@@ -426,13 +427,16 @@ int dvdcss_close_device ( dvdcss_t dvdcss )
free( dvdcss->p_readv_buffer );
dvdcss->p_readv_buffer = NULL;
dvdcss->i_readv_buf_size = 0;
-
- return 0;
#else
- close( dvdcss->i_fd );
+ i_ret = close( dvdcss->i_fd );
+ if( i_ret < 0 )
+ {
+ print_error( dvdcss, "Failed to close fd, data loss possible." );
+ return i_ret;
+ }
+#endif

return 0;
-#endif
}

/* Following functions are local */
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 44d740b..91f83cd 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -779,16 +779,15 @@ LIBDVDCSS_EXPORT int dvdcss_close ( dvdcss_t dvdcss )
p_title = p_tmptitle;
}

- i_ret = dvdcss_close_device( dvdcss );
+ free( dvdcss->psz_device );
+ free( dvdcss );

+ i_ret = dvdcss_close_device( dvdcss );
if( i_ret < 0 )
{
return i_ret;
}

- free( dvdcss->psz_device );
- free( dvdcss );
-
return 0;
}
Diego Biurrun
2014-11-14 10:44:58 UTC
Permalink
libdvdcss | branch: master | Diego Biurrun <***@biurrun.de> | Wed Nov 12 23:53:41 2014 +0100| [4102156b9f9029874d8e25776fbedcd7f8e15dee] | committer: Diego Biurrun

Properly check for and return errors from close().

Also fix a memory leak on close() failure.
http://git.videolan.org/gitweb.cgi/libdvdcss.git/?a=commit;h=4102156b9f9029874d8e25776fbedcd7f8e15dee
---

src/device.c | 12 ++++++++----
src/libdvdcss.c | 7 +------
2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/device.c b/src/device.c
index ddb216e..e824b54 100644
--- a/src/device.c
+++ b/src/device.c
@@ -412,6 +412,7 @@ int dvdcss_raw_open ( dvdcss_t dvdcss, const char *psz_device )

int dvdcss_close_device ( dvdcss_t dvdcss )
{
+ int i_ret;
#if defined( WIN32 )
if( dvdcss->b_file )
{
@@ -426,13 +427,16 @@ int dvdcss_close_device ( dvdcss_t dvdcss )
free( dvdcss->p_readv_buffer );
dvdcss->p_readv_buffer = NULL;
dvdcss->i_readv_buf_size = 0;
-
- return 0;
#else
- close( dvdcss->i_fd );
+ i_ret = close( dvdcss->i_fd );
+ if( i_ret < 0 )
+ {
+ print_error( dvdcss, "Failed to close fd, data loss possible." );
+ return i_ret;
+ }
+#endif

return 0;
-#endif
}

/* Following functions are local */
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 44d740b..0eb2298 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -781,15 +781,10 @@ LIBDVDCSS_EXPORT int dvdcss_close ( dvdcss_t dvdcss )

i_ret = dvdcss_close_device( dvdcss );

- if( i_ret < 0 )
- {
- return i_ret;
- }
-
free( dvdcss->psz_device );
free( dvdcss );

- return 0;
+ return i_ret;
}

/**
Diego Biurrun
2014-11-14 15:45:57 UTC
Permalink
libdvdcss | branch: master | Diego Biurrun <***@biurrun.de> | Wed Nov 12 23:53:41 2014 +0100| [76a8dee9721ac948f4e008f80ffe09c43b899586] | committer: Diego Biurrun

Properly check for and return errors from close().

Also fix a memory leak on close() failure.
http://git.videolan.org/gitweb.cgi/libdvdcss.git/?a=commit;h=76a8dee9721ac948f4e008f80ffe09c43b899586
---

src/device.c | 11 +++++++----
src/libdvdcss.c | 7 +------
2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/device.c b/src/device.c
index ddb216e..d62561c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -426,13 +426,16 @@ int dvdcss_close_device ( dvdcss_t dvdcss )
free( dvdcss->p_readv_buffer );
dvdcss->p_readv_buffer = NULL;
dvdcss->i_readv_buf_size = 0;
-
- return 0;
#else
- close( dvdcss->i_fd );
+ int i_ret = close( dvdcss->i_fd );
+ if( i_ret < 0 )
+ {
+ print_error( dvdcss, "Failed to close fd, data loss possible." );
+ return i_ret;
+ }
+#endif

return 0;
-#endif
}

/* Following functions are local */
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 44d740b..0eb2298 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -781,15 +781,10 @@ LIBDVDCSS_EXPORT int dvdcss_close ( dvdcss_t dvdcss )

i_ret = dvdcss_close_device( dvdcss );

- if( i_ret < 0 )
- {
- return i_ret;
- }
-
free( dvdcss->psz_device );
free( dvdcss );

- return 0;
+ return i_ret;
}

/**

Loading...