[libbluray-devel] [PATCH 2/3] bd_open: simplify

Rafaël Carré funman at videolan.org
Tue Dec 27 20:44:02 CET 2011


don't reinvent strdup
don't use calloc() if device_path is NULL
---
 src/libbluray/bluray.c |   29 +++++++++++++----------------
 1 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 506b98d..e733381 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -913,33 +913,30 @@ static void _fill_disc_info(BLURAY *bd)
 
 BLURAY *bd_open(const char* device_path, const char* keyfile_path)
 {
+    if (!device_path) {
+        BD_DEBUG(DBG_BLURAY | DBG_CRIT, "No device path provided!\n");
+        return NULL;
+    }
+
     BLURAY *bd = calloc(1, sizeof(BLURAY));
 
     BD_DEBUG(DBG_BLURAY, "libbluray version "BLURAY_VERSION_STRING"\n");
 
-    if (device_path) {
-
-        bd->device_path = (char*)malloc(strlen(device_path) + 1);
-        strcpy(bd->device_path, device_path);
+    bd->device_path = strdup(device_path);
 
-        _libaacs_open(bd, keyfile_path);
+    _libaacs_open(bd, keyfile_path);
 
-        _libbdplus_open(bd, keyfile_path);
+    _libbdplus_open(bd, keyfile_path);
 
-        _index_open(bd);
+    _index_open(bd);
 
-        bd->meta = NULL;
+    bd->meta = NULL;
 
-        bd->regs = bd_registers_init();
+    bd->regs = bd_registers_init();
 
-        _fill_disc_info(bd);
+    _fill_disc_info(bd);
 
-        BD_DEBUG(DBG_BLURAY, "BLURAY initialized! (%p)\n", bd);
-    } else {
-        X_FREE(bd);
-
-        BD_DEBUG(DBG_BLURAY | DBG_CRIT, "No device path provided!\n");
-    }
+    BD_DEBUG(DBG_BLURAY, "BLURAY initialized! (%p)\n", bd);
 
     return bd;
 }
-- 
1.7.7.3


More information about the libbluray-devel mailing list