plugins/elements/: Use gst_buffer_try_new_and_alloc() and handle errors instead of...
authorSebastian Dröge <slomo@circular-chaos.org>
Thu, 23 Oct 2008 12:52:58 +0000 (12:52 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Thu, 23 Oct 2008 12:52:58 +0000 (12:52 +0000)
Original commit message from CVS:
* plugins/elements/gstfdsrc.c: (gst_fd_src_create):
* plugins/elements/gstfilesrc.c: (gst_file_src_create_read):
Use gst_buffer_try_new_and_alloc() and handle errors instead of
using gst_buffer_new_and_alloc() which aborts if the buffer couldn't
be allocated.

ChangeLog
plugins/elements/gstfdsrc.c
plugins/elements/gstfilesrc.c

index fc3423b..1af9cb9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-10-23  Sebastian Dröge  <slomo@circular-chaos.org>
+
+       * plugins/elements/gstfdsrc.c: (gst_fd_src_create):
+       * plugins/elements/gstfilesrc.c: (gst_file_src_create_read):
+       Use gst_buffer_try_new_and_alloc() and handle errors instead of
+       using gst_buffer_new_and_alloc() which aborts if the buffer couldn't
+       be allocated.
+
 2008-10-23  Wim Taymans  <wim.taymans@collabora.co.uk>
 
        * gst/gstsegment.c: (gst_segment_set_newsegment_full):
index 4f6beb3..33fb5fd 100644 (file)
@@ -432,7 +432,11 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
   blocksize = GST_BASE_SRC (src)->blocksize;
 
   /* create the buffer */
-  buf = gst_buffer_new_and_alloc (blocksize);
+  buf = gst_buffer_try_new_and_alloc (blocksize);
+  if (G_UNLIKELY (buf == NULL)) {
+    GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", blocksize);
+    return GST_FLOW_ERROR;
+  }
 
   do {
     readbytes = read (src->fd, GST_BUFFER_DATA (buf), blocksize);
@@ -556,6 +560,7 @@ gst_fd_src_uri_get_type (void)
 {
   return GST_URI_SRC;
 }
+
 static gchar **
 gst_fd_src_uri_get_protocols (void)
 {
@@ -563,6 +568,7 @@ gst_fd_src_uri_get_protocols (void)
 
   return protocols;
 }
+
 static const gchar *
 gst_fd_src_uri_get_uri (GstURIHandler * handler)
 {
index cf3d5aa..f890fb9 100644 (file)
@@ -565,8 +565,8 @@ gst_mmap_buffer_finalize (GstMmapBuffer * mmap_buffer)
   GST_LOG ("unmapped region %08lx+%08lx at %p",
       (gulong) offset, (gulong) size, data);
 
-  GST_MINI_OBJECT_CLASS (mmap_buffer_parent_class)->
-      finalize (GST_MINI_OBJECT (mmap_buffer));
+  GST_MINI_OBJECT_CLASS (mmap_buffer_parent_class)->finalize (GST_MINI_OBJECT
+      (mmap_buffer));
 }
 
 static GstBuffer *
@@ -822,7 +822,11 @@ gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length,
     src->read_position = offset;
   }
 
-  buf = gst_buffer_new_and_alloc (length);
+  buf = gst_buffer_try_new_and_alloc (length);
+  if (G_UNLIKELY (buf == NULL && length > 0)) {
+    GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", length);
+    return GST_FLOW_ERROR;
+  }
 
   GST_LOG_OBJECT (src, "Reading %d bytes", length);
   ret = read (src->fd, GST_BUFFER_DATA (buf), length);
@@ -1076,6 +1080,7 @@ gst_file_src_uri_get_type (void)
 {
   return GST_URI_SRC;
 }
+
 static gchar **
 gst_file_src_uri_get_protocols (void)
 {
@@ -1083,6 +1088,7 @@ gst_file_src_uri_get_protocols (void)
 
   return protocols;
 }
+
 static const gchar *
 gst_file_src_uri_get_uri (GstURIHandler * handler)
 {