[libbluray-devel] disc: check memory allocations
hpi1
git at videolan.org
Sun May 17 12:22:54 CEST 2015
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun May 17 13:13:00 2015 +0300| [a508631b5f885d951c81e6bf02622157e13c42e0] | committer: hpi1
disc: check memory allocations
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=a508631b5f885d951c81e6bf02622157e13c42e0
---
src/libbluray/disc/aacs.c | 3 +++
src/libbluray/disc/bdplus.c | 21 ++++++++++++++-------
src/libbluray/disc/dec.c | 4 ++++
src/libbluray/disc/disc.c | 30 ++++++++++++++++++++++++++----
src/libbluray/disc/udf_fs.c | 6 ++++++
5 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/src/libbluray/disc/aacs.c b/src/libbluray/disc/aacs.c
index 217ef6f..3059d66 100644
--- a/src/libbluray/disc/aacs.c
+++ b/src/libbluray/disc/aacs.c
@@ -108,6 +108,9 @@ static void *_open_libaacs(void)
BD_AACS *libaacs_load(void)
{
BD_AACS *p = calloc(1, sizeof(BD_AACS));
+ if (!p) {
+ return NULL;
+ }
p->h_libaacs = _open_libaacs();
if (!p->h_libaacs) {
diff --git a/src/libbluray/disc/bdplus.c b/src/libbluray/disc/bdplus.c
index b8c4d57..363719f 100644
--- a/src/libbluray/disc/bdplus.c
+++ b/src/libbluray/disc/bdplus.c
@@ -107,6 +107,9 @@ static void *_libbdplus_open(void)
BD_BDPLUS *libbdplus_load(void)
{
BD_BDPLUS *p = calloc(1, sizeof(BD_BDPLUS));
+ if (!p) {
+ return NULL;
+ }
BD_DEBUG(DBG_BDPLUS, "attempting to load libbdplus\n");
@@ -241,10 +244,12 @@ BD_BDPLUS_ST *libbdplus_m2ts(BD_BDPLUS *p, uint32_t clip_id, uint64_t pos)
if (!p->m2ts) {
/* use old API */
BD_BDPLUS_ST *ret = calloc(1, sizeof(BD_BDPLUS_ST));
- ret->lib = p;
- ret->st = NULL;
- p->title(p->bdplus, clip_id);
- p->seek(p->bdplus, pos);
+ if (ret) {
+ ret->lib = p;
+ ret->st = NULL;
+ p->title(p->bdplus, clip_id);
+ p->seek(p->bdplus, pos);
+ }
return ret;
}
@@ -258,9 +263,11 @@ BD_BDPLUS_ST *libbdplus_m2ts(BD_BDPLUS *p, uint32_t clip_id, uint64_t pos)
p->m2ts_close(st);
} else {
BD_BDPLUS_ST *ret = calloc(1, sizeof(BD_BDPLUS_ST));
- ret->lib = p;
- ret->st = st;
- BD_DEBUG(DBG_BLURAY | DBG_CRIT, "BD+ active for clip %05d.m2ts\n", clip_id);
+ if (ret) {
+ ret->lib = p;
+ ret->st = st;
+ BD_DEBUG(DBG_BLURAY | DBG_CRIT, "BD+ active for clip %05d.m2ts\n", clip_id);
+ }
return ret;
}
}
diff --git a/src/libbluray/disc/dec.c b/src/libbluray/disc/dec.c
index 694646e..290dd4d 100644
--- a/src/libbluray/disc/dec.c
+++ b/src/libbluray/disc/dec.c
@@ -158,6 +158,10 @@ static int _bdrom_have_file(void *p, const char *dir, const char *file)
char *path;
path = str_printf("%s" DIR_SEP "%s", dir, file);
+ if (!path) {
+ return 0;
+ }
+
fp = dev->pf_file_open_bdrom(dev->file_open_bdrom_handle, path);
X_FREE(path);
diff --git a/src/libbluray/disc/disc.c b/src/libbluray/disc/disc.c
index ecd53e3..32295f2 100644
--- a/src/libbluray/disc/disc.c
+++ b/src/libbluray/disc/disc.c
@@ -65,6 +65,10 @@ static BD_FILE_H *_bdrom_open_path(void *p, const char *rel_path)
char *abs_path;
abs_path = str_printf("%s%s", disc->disc_root, rel_path);
+ if (!abs_path) {
+ return NULL;
+ }
+
fp = file_open(abs_path, "rb");
X_FREE(abs_path);
@@ -78,6 +82,10 @@ static BD_DIR_H *_bdrom_open_dir(void *p, const char *dir)
char *path;
path = str_printf("%s%s", disc->disc_root, dir);
+ if (!path) {
+ return NULL;
+ }
+
dp = dir_open(path);
X_FREE(path);
@@ -96,8 +104,10 @@ static BD_FILE_H *_overlay_open_path(BD_DISC *p, const char *rel_path)
if (p->overlay_root) {
char *abs_path = str_printf("%s%s", p->overlay_root, rel_path);
- fp = file_open(abs_path, "rb");
- X_FREE(abs_path);
+ if (abs_path) {
+ fp = file_open(abs_path, "rb");
+ X_FREE(abs_path);
+ }
}
bd_mutex_unlock(&p->ovl_mutex);
@@ -113,8 +123,10 @@ static BD_DIR_H *_overlay_open_dir(BD_DISC *p, const char *dir)
if (p->overlay_root) {
char *abs_path = str_printf("%s%s", p->disc_root, dir);
- dp = dir_open_default()(abs_path);
- X_FREE(abs_path);
+ if (abs_path) {
+ dp = dir_open_default()(abs_path);
+ X_FREE(abs_path);
+ }
}
bd_mutex_unlock(&p->ovl_mutex);
@@ -183,6 +195,10 @@ static BD_DIR_H *_combine_dirs(BD_DIR_H *ovl, BD_DIR_H *rom)
dp->read = _comb_dir_read;
dp->close = _comb_dir_close;
dp->internal = calloc(1, sizeof(COMB_DIR));
+ if (!dp->internal) {
+ X_FREE(dp);
+ goto out;
+ }
while (!dir_read(ovl, &entry)) {
_comb_dir_append(dp, &entry);
@@ -191,6 +207,8 @@ static BD_DIR_H *_combine_dirs(BD_DIR_H *ovl, BD_DIR_H *rom)
_comb_dir_append(dp, &entry);
}
}
+
+ out:
dir_close(ovl);
dir_close(rom);
@@ -342,6 +360,10 @@ BD_FILE_H *disc_open_file(BD_DISC *p, const char *dir, const char *file)
char *path;
path = str_printf("%s" DIR_SEP "%s", dir, file);
+ if (!path) {
+ return NULL;
+ }
+
fp = disc_open_path(p, path);
X_FREE(path);
diff --git a/src/libbluray/disc/udf_fs.c b/src/libbluray/disc/udf_fs.c
index 1eec761..3e438ca 100644
--- a/src/libbluray/disc/udf_fs.c
+++ b/src/libbluray/disc/udf_fs.c
@@ -67,6 +67,9 @@ static int64_t _file_read(BD_FILE_H *file, uint8_t *buf, int64_t size)
BD_FILE_H *udf_file_open(void *udf, const char *filename)
{
BD_FILE_H *file = calloc(1, sizeof(BD_FILE_H));
+ if (!file) {
+ return NULL;
+ }
BD_DEBUG(DBG_FILE, "Opening UDF file %s... (%p)\n", filename, (void*)file);
@@ -116,6 +119,9 @@ static int _dir_read(BD_DIR_H *dir, BD_DIRENT *entry)
BD_DIR_H *udf_dir_open(void *udf, const char* dirname)
{
BD_DIR_H *dir = calloc(1, sizeof(BD_DIR_H));
+ if (!dir) {
+ return NULL;
+ }
BD_DEBUG(DBG_DIR, "Opening UDF dir %s... (%p)\n", dirname, (void*)dir);
More information about the libbluray-devel
mailing list