[libbluray-devel] file: check for memory allocation failures
hpi1
git at videolan.org
Fri May 15 11:23:27 CEST 2015
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri May 15 12:07:08 2015 +0300| [2239e280287fc5ae380c9d060d95d800c2c3ea3d] | committer: hpi1
file: check for memory allocation failures
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=2239e280287fc5ae380c9d060d95d800c2c3ea3d
---
src/file/dir_posix.c | 4 ++++
src/file/dir_win32.c | 3 +++
src/file/dirs_xdg.c | 3 +++
src/file/dl_posix.c | 5 +++++
src/file/dl_win32.c | 5 +++++
5 files changed, 20 insertions(+)
diff --git a/src/file/dir_posix.c b/src/file/dir_posix.c
index fcb9c01..1592ec3 100644
--- a/src/file/dir_posix.c
+++ b/src/file/dir_posix.c
@@ -65,6 +65,10 @@ static BD_DIR_H *_dir_open_posix(const char* dirname)
BD_DIR_H *dir = calloc(1, sizeof(BD_DIR_H));
BD_DEBUG(DBG_DIR, "Opening POSIX dir %s... (%p)\n", dirname, (void*)dir);
+ if (!dir) {
+ return NULL;
+ }
+
dir->close = _dir_close_posix;
dir->read = _dir_read_posix;
diff --git a/src/file/dir_win32.c b/src/file/dir_win32.c
index fde0106..2690658 100644
--- a/src/file/dir_win32.c
+++ b/src/file/dir_win32.c
@@ -75,6 +75,9 @@ static BD_DIR_H *_dir_open_win32(const char* dirname)
BD_DIR_H *dir = calloc(1, sizeof(BD_DIR_H));
BD_DEBUG(DBG_DIR, "Opening WIN32 dir %s... (%p)\n", dirname, (void*)dir);
+ if (!dir) {
+ return NULL;
+ }
dir->close = _dir_close_win32;
dir->read = _dir_read_win32;
diff --git a/src/file/dirs_xdg.c b/src/file/dirs_xdg.c
index 0cca357..0ab3fdf 100644
--- a/src/file/dirs_xdg.c
+++ b/src/file/dirs_xdg.c
@@ -98,6 +98,9 @@ const char *file_get_config_system(const char *dir)
if (xdg_sys && *xdg_sys) {
dirs = calloc(1, strlen(xdg_sys) + 2);
+ if (!dirs) {
+ return NULL;
+ }
strcpy(dirs, xdg_sys);
char *pt = dirs;
diff --git a/src/file/dl_posix.c b/src/file/dl_posix.c
index 5be67ac..200a888 100644
--- a/src/file/dl_posix.c
+++ b/src/file/dl_posix.c
@@ -81,6 +81,11 @@ void *dl_dlopen(const char *path, const char *version)
name = str_printf("%s%s%s", search_paths[i], path, ext);
}
+ if (!name) {
+ BD_DEBUG(DBG_FILE | DBG_CRIT, "out of memory\n");
+ continue;
+ }
+
BD_DEBUG(DBG_FILE, "Attempting to open %s\n", name);
dll = _dl_dlopen (name);
diff --git a/src/file/dl_win32.c b/src/file/dl_win32.c
index fc8385f..e4492e1 100644
--- a/src/file/dl_win32.c
+++ b/src/file/dl_win32.c
@@ -62,6 +62,11 @@ void *dl_dlopen(const char *path, const char *version)
void *result;
name = str_printf("%s.dll", path);
+ if (!name) {
+ BD_DEBUG(DBG_FILE | DBG_CRIT, "out of memory\n");
+ return NULL;
+ }
+
MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, MAX_PATH);
X_FREE(name);
More information about the libbluray-devel
mailing list