From 728becfdd53adedd2fdd5cd80a3721fb464f8d67 Mon Sep 17 00:00:00 2001 From: SeokHoon Lee Date: Thu, 26 Apr 2018 13:10:37 +0900 Subject: [PATCH] Change malloc to g_malloc - malloc has changed to g_malloc - add null check routine Signed-off-by: SeokHoon Lee Change-Id: Idb2eea4312092f519e35be167a9292d5ae462b1f --- wfdmanager/wfdsrc/gstwfdsrc.c | 105 ++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 70 deletions(-) diff --git a/wfdmanager/wfdsrc/gstwfdsrc.c b/wfdmanager/wfdsrc/gstwfdsrc.c index b45cb87..7ff2b46 100644 --- a/wfdmanager/wfdsrc/gstwfdsrc.c +++ b/wfdmanager/wfdsrc/gstwfdsrc.c @@ -1050,13 +1050,14 @@ gst_wfd_src_prepare_tcp (GstWFDBaseSrc *bsrc, gint rtpport) static GstFlowReturn gst_wfd_src_loop_tcp (GstWFDSrc *src) { +#define RTSP_HEADER_SIZE 4 GstRTSPResult res; GstPad *outpad = NULL; GstFlowReturn ret = GST_FLOW_OK; - guint8 *sizedata, *datatmp; - gint message_size_length = 2, message_size; + guint8 *rtsp_message; + gint message_size; + guint8 rtsp_header[RTSP_HEADER_SIZE]; GstBuffer *buf; - GstMapInfo map; GTimeVal tv_timeout; if (!src->tcp_connection) @@ -1071,86 +1072,50 @@ gst_wfd_src_loop_tcp (GstWFDSrc *src) tv_timeout.tv_sec, tv_timeout.tv_usec); } - /* Read 2 bytes message type in begining */ - sizedata = (guint8 *)malloc (message_size_length); - if((res = gst_rtsp_connection_read (src->tcp_connection,sizedata, message_size_length, &tv_timeout)) - !=GST_RTSP_OK){ - ret = GST_FLOW_ERROR; - switch (res) { - case GST_RTSP_EINTR: - { - GST_ERROR ("Got interrupted\n"); - if (src->tcp_connection) - gst_rtsp_connection_flush (src->tcp_connection, FALSE); - break; - } - default: - { - GST_ERROR ("Got error %d\n", res); - break; - } + /* Read 2 bytes message type + 2 bytes message size in begining */ + res = gst_rtsp_connection_read (src->tcp_connection, rtsp_header, RTSP_HEADER_SIZE, &tv_timeout); + + if (res != GST_RTSP_OK) { + + if (res == GST_RTSP_EINTR) { + GST_ERROR ("Got interrupted\n"); + gst_rtsp_connection_flush (src->tcp_connection, FALSE); } - g_free(sizedata); - return ret; + + GST_ERROR ("Got error %d\n", res); + return GST_FLOW_ERROR; } - /*In rtp message over TCP the first 2 bytes are message size. - * * So firtstly read rtp message size.*/ - if((res = gst_rtsp_connection_read (src->tcp_connection,sizedata, message_size_length, &tv_timeout)) - !=GST_RTSP_OK){ - ret = GST_FLOW_ERROR; - switch (res) { - case GST_RTSP_EINTR: - { - GST_ERROR ("Got interrupted\n"); - if (src->tcp_connection) - gst_rtsp_connection_flush (src->tcp_connection, FALSE); - break; - } - default: - { - GST_ERROR ("Got error %d\n", res); - break; - } - } - g_free(sizedata); - return ret; + + message_size = ((guint)rtsp_header[2] << 8) | rtsp_header[3]; + + rtsp_message = g_malloc (message_size); + if (rtsp_message == NULL) { + GST_ERROR ("Out of memory for rtsp_message, size = %d\n", message_size); + return GST_FLOW_ERROR; } - message_size = ((guint)sizedata[0] << 8) | sizedata[1]; - datatmp = (guint8 *) malloc (message_size); - g_free(sizedata); - if((res = gst_rtsp_connection_read (src->tcp_connection,datatmp,message_size, &tv_timeout)) - !=GST_RTSP_OK){ - ret = GST_FLOW_ERROR; - switch (res) { - case GST_RTSP_EINTR: - { - GST_ERROR ("Got interrupted\n"); - if (src->tcp_connection) - gst_rtsp_connection_flush (src->tcp_connection, FALSE); - break; - } - default: - { - GST_ERROR ("Got error %d\n", res); - break; - } + res = gst_rtsp_connection_read (src->tcp_connection, rtsp_message, message_size, &tv_timeout); + + if (res != GST_RTSP_OK) { + + if (res == GST_RTSP_EINTR) { + GST_ERROR ("Got interrupted\n"); + gst_rtsp_connection_flush (src->tcp_connection, FALSE); } - g_free(datatmp); - return ret; + + GST_ERROR ("Got error %d\n", res); + g_free(rtsp_message); + return GST_FLOW_ERROR; } /*first byte of data is type of payload * * 200 is rtcp type then we need other pad*/ - if(datatmp[0] == 200) + if (rtsp_message[0] == 200) outpad = src->channelpad[1]; else outpad = src->channelpad[0]; - buf = gst_buffer_new_wrapped(datatmp, message_size); - gst_buffer_map(buf, &map, GST_MAP_READ); - - gst_buffer_unmap(buf, &map); + buf = gst_buffer_new_wrapped (rtsp_message, message_size); if (src->discont) { GstClockTime now; -- 2.7.4