ext/: Use gst_buffer_try_new_and_alloc() and fail properly if the allocation failed...
authorSebastian Dröge <slomo@circular-chaos.org>
Mon, 24 Nov 2008 12:07:10 +0000 (12:07 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Mon, 24 Nov 2008 12:07:10 +0000 (12:07 +0000)
Original commit message from CVS:
* ext/gio/gstgiobasesrc.c: (gst_gio_base_src_create):
* ext/gnomevfs/gstgnomevfssrc.c: (gst_gnome_vfs_src_create):
Use gst_buffer_try_new_and_alloc() and fail properly if the
allocation failed. This prevents abort() if downstream elements
request an insane amount of memory.

ChangeLog
ext/gio/gstgiobasesrc.c
ext/gnomevfs/gstgnomevfssrc.c

index c55118e..a5a097a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-11-24  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
+
+       * ext/gio/gstgiobasesrc.c: (gst_gio_base_src_create):
+       * ext/gnomevfs/gstgnomevfssrc.c: (gst_gnome_vfs_src_create):
+       Use gst_buffer_try_new_and_alloc() and fail properly if the
+       allocation failed. This prevents abort() if downstream elements
+       request an insane amount of memory.
+
 2008-11-24  Wim Taymans  <wim.taymans@collabora.co.uk>
 
        * gst/volume/gstvolume.c: (volume_choose_func),
index bd9ebdd..e301e30 100644 (file)
@@ -317,9 +317,7 @@ gst_gio_base_src_create (GstBaseSrc * base_src, guint64 offset, guint size,
     GstBuffer ** buf_return)
 {
   GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src);
-
   GstBuffer *buf;
-
   GstFlowReturn ret = GST_FLOW_OK;
 
   g_return_val_if_fail (G_IS_INPUT_STREAM (src->stream), GST_FLOW_ERROR);
@@ -369,7 +367,11 @@ gst_gio_base_src_create (GstBaseSrc * base_src, guint64 offset, guint size,
         return ret;
     }
 
-    src->cache = gst_buffer_new_and_alloc (cachesize);
+    src->cache = gst_buffer_try_new_and_alloc (cachesize);
+    if (G_UNLIKELY (src->cache == NULL)) {
+      GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", cachesize);
+      return GST_FLOW_ERROR;
+    }
 
     GST_LOG_OBJECT (src, "Reading %u bytes from offset %" G_GUINT64_FORMAT,
         cachesize, offset);
index beb323d..e4bb530 100644 (file)
@@ -625,7 +625,11 @@ gst_gnome_vfs_src_create (GstBaseSrc * basesrc, guint64 offset, guint size,
     }
   }
 
-  buf = gst_buffer_new_and_alloc (size);
+  buf = gst_buffer_try_new_and_alloc (size);
+  if (G_UNLIKELY (buf == NULL && size == 0)) {
+    GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
+    return GST_FLOW_ERROR;
+  }
 
   data = GST_BUFFER_DATA (buf);