Commit 3c43b555 authored by Petri Hintukainen's avatar Petri Hintukainen

Check calloc result

parent ebdcfe27
......@@ -464,6 +464,11 @@ static int _create_jvm(void *jvm_lib, const char *java_home, const char *jar_fil
}
JavaVMOption* option = calloc(1, sizeof(JavaVMOption) * 20);
if (!option) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
return 0;
}
int n = 0;
JavaVMInitArgs args;
option[n++].optionString = str_dup ("-Dawt.toolkit=java.awt.BDToolkit");
......@@ -538,16 +543,22 @@ BDJAVA* bdj_open(const char *path, struct bluray *bd,
return 0;
}
BDJAVA* bdjava = calloc(1, sizeof(BDJAVA));
if (!bdjava) {
dl_dlclose(jvm_lib);
return NULL;
}
JNIEnv* env = NULL;
JavaVM *jvm = NULL;
if (!_find_jvm(jvm_lib, &env, &jvm) &&
!_create_jvm(jvm_lib, java_home, jar_file, &env, &jvm)) {
X_FREE(bdjava);
dl_dlclose(jvm_lib);
return NULL;
}
BDJAVA* bdjava = calloc(1, sizeof(BDJAVA));
bdjava->h_libjvm = jvm_lib;
bdjava->jvm = jvm;
......
......@@ -103,8 +103,16 @@ static int _parse_index(BITSTREAM *bs, INDX_ROOT *index)
}
index->num_titles = bs_read(bs, 16);
if (!index->num_titles) {
BD_DEBUG(DBG_CRIT, "empty index\n");
return 0;
}
index->titles = calloc(index->num_titles, sizeof(INDX_TITLE));
if (!index->titles) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
return 0;
}
for (i = 0; i < index->num_titles; i++) {
......
......@@ -145,6 +145,10 @@ META_ROOT *meta_parse(BD_DISC *disc)
{
#ifdef HAVE_LIBXML2
META_ROOT *root = calloc(1, sizeof(META_ROOT));
if (!root) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
return NULL;
}
root->dl_count = 0;
xmlDocPtr doc;
......
......@@ -103,7 +103,15 @@ static int _sound_read_samples(BITSTREAM *bs, SOUND_OBJECT *obj)
uint32_t n;
uint32_t num_samples = obj->num_frames * obj->num_channels;
if (!num_samples) {
return 1;
}
obj->samples = calloc(num_samples, sizeof(uint16_t));
if (!obj->samples) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
return 0;
}
for (n = 0; n < num_samples; n++) {
obj->samples[n] = bs_read(bs, 16);
......@@ -116,13 +124,14 @@ void sound_free(SOUND_DATA **p)
{
if (p && *p) {
unsigned i;
for (i = 0 ; i < (*p)->num_sounds; i++) {
X_FREE((*p)->sounds[i].samples);
}
X_FREE((*p)->sounds);
if ((*p)->sounds) {
unsigned i;
for (i = 0 ; i < (*p)->num_sounds; i++) {
X_FREE((*p)->sounds[i].samples);
}
X_FREE((*p)->sounds);
}
X_FREE(*p);
}
}
......@@ -150,21 +159,29 @@ static SOUND_DATA *_sound_parse(BD_FILE_H *fp)
bs_skip(&bs, 8); /* reserved */
num_sounds = bs_read(&bs, 8);
if (data_len < 1) {
if (data_len < 1 || num_sounds < 1) {
BD_DEBUG(DBG_NAV | DBG_CRIT, "empty database\n");
goto error;
}
data_offsets = calloc(num_sounds, sizeof(uint32_t));
data = calloc(1, sizeof(SOUND_DATA));
if (!data_offsets | !data) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
goto error;
}
data->num_sounds = num_sounds;
data->sounds = calloc(num_sounds, sizeof(SOUND_OBJECT));
if (!data->sounds) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
goto error;
}
/* parse headers */
for (i = 0; i < data->num_sounds; i++) {
if (!_sound_parse_index(&bs, data_offsets + i, &data->sounds[i])) {
BD_DEBUG(DBG_NAV | DBG_CRIT, "error parsing sound %d attribues\n", i);
BD_DEBUG(DBG_NAV | DBG_CRIT, "error parsing sound %d attributes\n", i);
goto error;
}
}
......
......@@ -202,7 +202,9 @@ static void _init_event_queue(BLURAY *bd)
{
if (!bd->event_queue) {
bd->event_queue = calloc(1, sizeof(struct bd_event_queue_s));
bd_mutex_init(&bd->event_queue->mutex);
if (bd->event_queue) {
bd_mutex_init(&bd->event_queue->mutex);
}
} else {
bd_mutex_lock(&bd->event_queue->mutex);
bd->event_queue->in = 0;
......
......@@ -74,6 +74,10 @@ TEXTST_RENDER *textst_render_init(void)
#ifdef HAVE_FT2
TEXTST_RENDER *p = calloc(1, sizeof(TEXTST_RENDER));
if (!p) {
return NULL;
}
if (!FT_Init_FreeType(&p->ft_lib)) {
return p;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment