[libbluray-devel] registers: check for memory allocation failures

hpi1 git at videolan.org
Wed Jan 22 12:49:42 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Jan 21 10:29:57 2014 +0200| [92ae519ea509a5b3b1a3df1fbcbe2f6b9827dc7e] | committer: hpi1

registers: check for memory allocation failures

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=92ae519ea509a5b3b1a3df1fbcbe2f6b9827dc7e
---

 src/libbluray/bluray.c   |    9 +++++++--
 src/libbluray/register.c |   16 +++++++++++-----
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 03c130a..ef75edb 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -1263,6 +1263,13 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
         return NULL;
     }
 
+    bd->regs = bd_registers_init();
+    if (!bd->regs) {
+        BD_DEBUG(DBG_BLURAY, "bd_registers_init() failed\n");
+        X_FREE(bd);
+        return NULL;
+    }
+
     bd->device_path = str_dup(device_path);
 
 #if (defined HAVE_MNTENT_H || defined __APPLE__)
@@ -1271,8 +1278,6 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
 
     _libaacs_init(bd, keyfile_path);
 
-    bd->regs = bd_registers_init();
-
     _libbdplus_init(bd);
 
     _index_open(bd);
diff --git a/src/libbluray/register.c b/src/libbluray/register.c
index 43751d4..77b3575 100644
--- a/src/libbluray/register.c
+++ b/src/libbluray/register.c
@@ -165,9 +165,11 @@ BD_REGISTERS *bd_registers_init(void)
 {
     BD_REGISTERS *p = calloc(1, sizeof(BD_REGISTERS));
 
-    memcpy(p->psr, bd_psr_init, sizeof(bd_psr_init));
+    if (p) {
+        memcpy(p->psr, bd_psr_init, sizeof(bd_psr_init));
 
-    bd_mutex_init(&p->mutex);
+        bd_mutex_init(&p->mutex);
+    }
 
     return p;
 }
@@ -218,9 +220,13 @@ void bd_psr_register_cb  (BD_REGISTERS *p, void (*callback)(void*,BD_PSR_EVENT*)
 
     p->num_cb++;
     p->cb = realloc(p->cb, p->num_cb * sizeof(PSR_CB_DATA));
-
-    p->cb[p->num_cb - 1].cb     = callback;
-    p->cb[p->num_cb - 1].handle = cb_handle;
+    if (p->cb) {
+        p->cb[p->num_cb - 1].cb     = callback;
+        p->cb[p->num_cb - 1].handle = cb_handle;
+    } else {
+        BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_psr_register_cb(): realloc failed\n");
+        p->num_cb = 0;
+    }
 
     bd_psr_unlock(p);
 }



More information about the libbluray-devel mailing list