[libdvdnav-devel] dvdnav_open: factorize the error path

Jean-Baptiste Kempf git at videolan.org
Thu Jul 31 02:02:04 CEST 2014


libdvdnav | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Jul 31 01:56:55 2014 +0200| [6b467b9935aa2adcf670c4e8bebf15e975218c1f] | committer: Jean-Baptiste Kempf

dvdnav_open: factorize the error path

And fail in new error cases

> http://git.videolan.org/gitweb.cgi/libdvdnav.git/?a=commit;h=6b467b9935aa2adcf670c4e8bebf15e975218c1f
---

 src/dvdnav.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/dvdnav.c b/src/dvdnav.c
index 33367db..9212eeb 100644
--- a/src/dvdnav.c
+++ b/src/dvdnav.c
@@ -150,28 +150,25 @@ dvdnav_status_t dvdnav_open(dvdnav_t** dest, const char *path) {
   this->vm = vm_new_vm();
   if(!this->vm) {
     printerr("Error initialising the DVD VM.");
-    pthread_mutex_destroy(&this->vm_lock);
-    free(this);
-    return DVDNAV_STATUS_ERR;
+    goto fail;
   }
   if(!vm_reset(this->vm, path)) {
     printerr("Error starting the VM / opening the DVD device.");
-    pthread_mutex_destroy(&this->vm_lock);
-    vm_free_vm(this->vm);
-    free(this);
-    return DVDNAV_STATUS_ERR;
+    goto fail;
   }
 
   /* Set the path. */
   this->path = strdup(path);
   if(!this->path)
-    return DVDNAV_STATUS_ERR;
+    goto fail;
 
   /* Pre-open and close a file so that the CSS-keys are cached. */
   this->file = DVDOpenFile(vm_get_dvd_reader(this->vm), 0, DVD_READ_MENU_VOBS);
 
   /* Start the read-ahead cache. */
   this->cache = dvdnav_read_cache_new(this);
+  if(!this->cache)
+    goto fail;
 
   /* Seed the random numbers. So that the DVD VM Command rand()
    * gives a different start value each time a DVD is played. */
@@ -182,6 +179,12 @@ dvdnav_status_t dvdnav_open(dvdnav_t** dest, const char *path) {
 
   (*dest) = this;
   return DVDNAV_STATUS_OK;
+
+fail:
+  pthread_mutex_destroy(&this->vm_lock);
+  vm_free_vm(this->vm);
+  free(this);
+  return DVDNAV_STATUS_ERR;
 }
 
 dvdnav_status_t dvdnav_close(dvdnav_t *this) {



More information about the libdvdnav-devel mailing list