# HG changeset patch
# User Darren Salt <linux@youmustbejoking.demon.co.uk>
# Date 1218645184 -3600
# Node ID 35f09930323e46c92e521846b9ccdfd5e277ad16
# Parent  a0830dddbd35625069506a9c49321317cbab8a2d
Check for allocation failures.

diff --git a/src/demuxers/demux_mng.c b/src/demuxers/demux_mng.c
--- a/src/demuxers/demux_mng.c
+++ b/src/demuxers/demux_mng.c
@@ -116,7 +116,9 @@ static mng_bool mymng_process_header(mng
   this->bih.biHeight = height;
   this->left_edge = (this->bih.biWidth - width) / 2;
 
-  this->image = malloc(this->bih.biWidth * height * 3);
+  this->image = malloc((mng_size_t)this->bih.biWidth * (mng_size_t)height * 3);
+  if (!this->image)
+    return MNG_FALSE;
 
   mng_set_canvasstyle(mngh, MNG_CANVAS_RGB8);
 
diff --git a/src/demuxers/demux_mod.c b/src/demuxers/demux_mod.c
--- a/src/demuxers/demux_mod.c
+++ b/src/demuxers/demux_mod.c
@@ -134,7 +134,11 @@ static int open_mod_file(demux_mod_t *th
   /* Get size and create buffer */
   this->filesize = this->input->get_length(this->input);
   this->buffer = (char *)malloc(this->filesize);
-  
+  if(!this->buffer) {
+    xine_log(this->stream->xine, XINE_LOG_PLUGIN, "modplug - allocation failure\n");
+    return 0;
+  }
+
   /* Seek to beginning */
   this->input->seek(this->input, 0, SEEK_SET);
   
diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c
--- a/src/demuxers/demux_real.c
+++ b/src/demuxers/demux_real.c
@@ -364,6 +364,10 @@ static void real_parse_audio_specific_da
   stream->frame_buffer = calloc(stream->frame_size, 1);
   stream->frame_num_bytes = 0;
   stream->sub_packet_cnt = 0;
+
+  if (!stream->frame_buffer)
+    xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
+	     "demux_real: failed to allocate the audio frame buffer!\n");
 
   xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
            "demux_real: buf type 0x%08x frame size %zu block align %d\n", stream->buf_type,
@@ -1373,6 +1377,11 @@ static int demux_real_send_chunk(demux_p
       int x;
       off_t pos;
 
+      if (!buffer) {
+        this->status = DEMUX_FINISHED;
+        return this->status;
+      }
+
       switch (this->audio_stream->buf_type) {
       case BUF_AUDIO_28_8:
 	for (x = 0; x < sph / 2; x++) {
