summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2013-04-15 15:37:17 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2013-04-15 15:37:17 +0200
commit04d5dafa7141e933f320a923e2e1f52d2adcea84 (patch)
treed4434ee426975612935caef89008a4d661bd8ed5
parent83a877daf6c2fb457b7364558fe55c3feb95cef3 (diff)
sdp: dynamically allocate buffers
Remove the static maximum buffer size and replace with dynamic allocation of as much bytes as needed. Also avoids doing large allocations on the stack.
-rw-r--r--gst-libs/gst/sdp/gstsdpmessage.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/gst-libs/gst/sdp/gstsdpmessage.c b/gst-libs/gst/sdp/gstsdpmessage.c
index e20c5b4dd..121aef7fe 100644
--- a/gst-libs/gst/sdp/gstsdpmessage.c
+++ b/gst-libs/gst/sdp/gstsdpmessage.c
@@ -65,9 +65,6 @@
#include "gstsdpmessage.h"
-/* FIXME, is currently allocated on the stack */
-#define MAX_LINE_LEN 1024 * 16
-
#define FREE_STRING(field) g_free (field); (field) = NULL
#define REPLACE_STRING(field, val) FREE_STRING(field); (field) = g_strdup (val)
@@ -2111,7 +2108,7 @@ gst_sdp_parse_line (SDPContext * c, gchar type, gchar * buffer)
}
case 'b':
{
- gchar str2[MAX_LINE_LEN];
+ gchar str2[32];
read_string_del (str, sizeof (str), ':', &p);
if (*p != '\0')
@@ -2189,11 +2186,12 @@ GstSDPResult
gst_sdp_message_parse_buffer (const guint8 * data, guint size,
GstSDPMessage * msg)
{
- gchar *p;
+ gchar *p, *s;
SDPContext c;
gchar type;
- gchar buffer[MAX_LINE_LEN];
- guint idx = 0;
+ gchar *buffer = NULL;
+ guint bufsize = 0;
+ guint len = 0;
g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
g_return_val_if_fail (data != NULL, GST_SDP_EINVAL);
@@ -2216,13 +2214,18 @@ gst_sdp_message_parse_buffer (const guint8 * data, guint size,
goto line_done;
p++;
- idx = 0;
- while (*p != '\n' && *p != '\r' && *p != '\0') {
- if (idx < sizeof (buffer) - 1)
- buffer[idx++] = *p;
+ s = p;
+ while (*p != '\n' && *p != '\r' && *p != '\0')
p++;
+
+ len = p - s;
+ if (bufsize <= len) {
+ buffer = g_malloc (len + 1);
+ bufsize = len + 1;
}
- buffer[idx] = '\0';
+ memcpy (buffer, s, len);
+ buffer[len] = '\0';
+
gst_sdp_parse_line (&c, type, buffer);
line_done:
@@ -2232,6 +2235,9 @@ gst_sdp_message_parse_buffer (const guint8 * data, guint size,
p++;
}
+ if (buffer)
+ g_free (buffer);
+
return GST_SDP_OK;
}