From f2dc9b2b8f9b8b180f41e0ae88d52229653c21b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 27 Nov 2014 18:04:58 +0100 Subject: [PATCH] glmemory: Use g_try_malloc() in the appropriate places g_malloc() aborts if allocation fails, it's pointless to check against NULL afterwards. That's why g_try_malloc() exists. --- gst-libs/gst/gl/gstglmemory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gst-libs/gst/gl/gstglmemory.c b/gst-libs/gst/gl/gstglmemory.c index 064af6e4b9..cc5b6e162d 100644 --- a/gst-libs/gst/gl/gstglmemory.c +++ b/gst-libs/gst/gl/gstglmemory.c @@ -852,7 +852,12 @@ _gl_mem_copy (GstGLMemory * src, gssize offset, gssize size) if (GST_GL_MEMORY_FLAG_IS_SET (src, GST_GL_MEMORY_FLAG_NEED_UPLOAD)) { dest = _gl_mem_new (src->mem.allocator, NULL, src->context, &src->info, src->plane, NULL, NULL); - dest->data = g_malloc (src->mem.maxsize); + dest->data = g_try_malloc (src->mem.maxsize); + if (dest->data == NULL) { + GST_CAT_WARNING (GST_CAT_GL_MEMORY, "Could not copy GL Memory"); + gst_memory_unref ((GstMemory *) dest); + return NULL; + } memcpy (dest->data, src->data, src->mem.maxsize); GST_GL_MEMORY_FLAG_SET (dest, GST_GL_MEMORY_FLAG_NEED_UPLOAD); } else { @@ -879,7 +884,7 @@ _gl_mem_copy (GstGLMemory * src, gssize offset, gssize size) } dest->tex_id = copy_params.tex_id; - dest->data = g_malloc (src->mem.maxsize); + dest->data = g_try_malloc (src->mem.maxsize); if (dest->data == NULL) { GST_CAT_WARNING (GST_CAT_GL_MEMORY, "Could not copy GL Memory"); gst_memory_unref ((GstMemory *) dest); @@ -1005,7 +1010,7 @@ gst_gl_memory_wrapped_texture (GstGLContext * context, guint texture_id, mem->tex_id = texture_id; mem->texture_wrapped = TRUE; - mem->data = g_malloc (mem->mem.maxsize); + mem->data = g_try_malloc (mem->mem.maxsize); if (mem->data == NULL) { gst_memory_unref ((GstMemory *) mem); return NULL; @@ -1031,7 +1036,7 @@ gst_gl_memory_alloc (GstGLContext * context, GstVideoInfo * info, guint plane) mem = _gl_mem_new (_gl_allocator, NULL, context, info, plane, NULL, NULL); - mem->data = g_malloc (mem->mem.maxsize); + mem->data = g_try_malloc (mem->mem.maxsize); if (mem->data == NULL) { gst_memory_unref ((GstMemory *) mem); return NULL;