summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2014-09-03 23:38:07 -0700
committerDavid Schleef <ds@schleef.org>2014-09-03 23:38:07 -0700
commitfadc1313a96ad5df14322af4a3f92a8580f9ca16 (patch)
treeec2115607149576fc9ff5d45ebb159e9aff991f3
parent9c324004d85f3fd61ea23e12c1752eb163f03e32 (diff)
hacking. fix memleaks
-rw-r--r--plugins/gstrtmp2sink.c26
-rw-r--r--plugins/gstrtmp2src.c12
-rw-r--r--rtmp/amf.c6
-rw-r--r--rtmp/rtmpchunk.c24
-rw-r--r--rtmp/rtmpclient.c1
-rw-r--r--rtmp/rtmpconnection.c25
-rw-r--r--rtmp/rtmputils.c2
7 files changed, 61 insertions, 35 deletions
diff --git a/plugins/gstrtmp2sink.c b/plugins/gstrtmp2sink.c
index d7c0777..c9f15a3 100644
--- a/plugins/gstrtmp2sink.c
+++ b/plugins/gstrtmp2sink.c
@@ -313,6 +313,11 @@ gst_rtmp2_sink_finalize (GObject * object)
GST_DEBUG_OBJECT (rtmp2sink, "finalize");
/* clean up object here */
+ g_free (rtmp2sink->uri);
+ g_free (rtmp2sink->server_address);
+ g_free (rtmp2sink->application);
+ g_free (rtmp2sink->stream);
+ g_free (rtmp2sink->secure_token);
g_object_unref (rtmp2sink->task);
g_rec_mutex_clear (&rtmp2sink->task_lock);
g_object_unref (rtmp2sink->client);
@@ -378,6 +383,10 @@ gst_rtmp2_sink_unlock (GstBaseSink * sink)
g_mutex_lock (&rtmp2sink->lock);
rtmp2sink->reset = TRUE;
+ gst_task_stop (rtmp2sink->task);
+ if (rtmp2sink->task_main_loop) {
+ g_main_loop_quit (rtmp2sink->task_main_loop);
+ }
g_cond_signal (&rtmp2sink->cond);
g_mutex_unlock (&rtmp2sink->lock);
@@ -394,10 +403,6 @@ gst_rtmp2_sink_unlock_stop (GstBaseSink * sink)
GST_DEBUG_OBJECT (rtmp2sink, "unlock_stop");
- gst_task_stop (rtmp2sink->task);
- if (rtmp2sink->task_main_loop) {
- g_main_loop_quit (rtmp2sink->task_main_loop);
- }
return TRUE;
}
@@ -470,6 +475,7 @@ gst_rtmp2_sink_render (GstBaseSink * sink, GstBuffer * buffer)
chunk->message_type_id = data[0];
chunk->chunk_stream_id = 4;
if (chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_DATA ||
+ chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_AUDIO ||
chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_VIDEO) {
} else {
GST_ERROR ("unknown message_type_id %d", chunk->message_type_id);
@@ -502,6 +508,7 @@ gst_rtmp2_sink_render (GstBaseSink * sink, GstBuffer * buffer)
} else {
bytes = g_bytes_new_take (data, size);
chunk->payload = g_bytes_new_from_bytes (bytes, 11, size - 15);
+ g_bytes_unref (bytes);
}
if (rtmp2sink->dump) {
@@ -680,6 +687,7 @@ send_connect (GstRtmp2Sink * rtmp2sink)
// "videoFunction": 1,
gst_rtmp_connection_send_command (rtmp2sink->connection, 3, "connect", 1,
node, NULL, cmd_connect_done, rtmp2sink);
+ gst_amf_node_free (node);
}
static void
@@ -733,16 +741,21 @@ send_create_stream (GstRtmp2Sink * rtmp2sink)
gst_amf_node_set_string (node2, rtmp2sink->stream);
gst_rtmp_connection_send_command (rtmp2sink->connection, 3, "releaseStream",
2, node, node2, NULL, NULL);
+ gst_amf_node_free (node);
+ gst_amf_node_free (node2);
node = gst_amf_node_new (GST_AMF_TYPE_NULL);
node2 = gst_amf_node_new (GST_AMF_TYPE_STRING);
gst_amf_node_set_string (node2, rtmp2sink->stream);
gst_rtmp_connection_send_command (rtmp2sink->connection, 3, "FCPublish", 3,
node, node2, NULL, NULL);
+ gst_amf_node_free (node);
+ gst_amf_node_free (node2);
node = gst_amf_node_new (GST_AMF_TYPE_NULL);
gst_rtmp_connection_send_command (rtmp2sink->connection, 3, "createStream", 4,
node, NULL, create_stream_done, rtmp2sink);
+ gst_amf_node_free (node);
}
static void
@@ -782,6 +795,9 @@ send_publish (GstRtmp2Sink * rtmp2sink)
gst_amf_node_set_string (node3, rtmp2sink->application);
gst_rtmp_connection_send_command2 (rtmp2sink->connection, 4, 1, "publish", 5,
node, node2, node3, NULL, publish_done, rtmp2sink);
+ gst_amf_node_free (node);
+ gst_amf_node_free (node2);
+ gst_amf_node_free (node3);
}
static void
@@ -846,5 +862,7 @@ send_secure_token_response (GstRtmp2Sink * rtmp2sink, const char *challenge)
gst_rtmp_connection_send_command (rtmp2sink->connection, 3,
"secureTokenResponse", 0, node1, node2, NULL, NULL);
+ gst_amf_node_free (node1);
+ gst_amf_node_free (node2);
}
diff --git a/plugins/gstrtmp2src.c b/plugins/gstrtmp2src.c
index ebab57d..b2dfe00 100644
--- a/plugins/gstrtmp2src.c
+++ b/plugins/gstrtmp2src.c
@@ -336,6 +336,11 @@ gst_rtmp2_src_finalize (GObject * object)
GST_DEBUG_OBJECT (rtmp2src, "finalize");
/* clean up object here */
+ g_free (rtmp2src->uri);
+ g_free (rtmp2src->server_address);
+ g_free (rtmp2src->application);
+ g_free (rtmp2src->stream);
+ g_free (rtmp2src->secure_token);
g_object_unref (rtmp2src->task);
g_rec_mutex_clear (&rtmp2src->task_lock);
g_object_unref (rtmp2src->client);
@@ -449,6 +454,7 @@ send_connect (GstRtmp2Src * rtmp2src)
// "videoFunction": 1,
gst_rtmp_connection_send_command (rtmp2src->connection, 3, "connect", 1, node,
NULL, cmd_connect_done, rtmp2src);
+ gst_amf_node_free (node);
}
static void
@@ -499,6 +505,7 @@ send_create_stream (GstRtmp2Src * rtmp2src)
node = gst_amf_node_new (GST_AMF_TYPE_NULL);
gst_rtmp_connection_send_command (rtmp2src->connection, 3, "createStream", 2,
node, NULL, create_stream_done, rtmp2src);
+ gst_amf_node_free (node);
}
@@ -539,6 +546,9 @@ send_play (GstRtmp2Src * rtmp2src)
gst_amf_node_set_number (n3, 0);
gst_rtmp_connection_send_command2 (rtmp2src->connection, 8, 1, "play", 3, n1,
n2, n3, NULL, play_done, rtmp2src);
+ gst_amf_node_free (n1);
+ gst_amf_node_free (n2);
+ gst_amf_node_free (n3);
}
@@ -883,5 +893,7 @@ send_secure_token_response (GstRtmp2Src * rtmp2src, const char *challenge)
gst_rtmp_connection_send_command (rtmp2src->connection, 3,
"secureTokenResponse", 0, node1, node2, NULL, NULL);
+ gst_amf_node_free (node1);
+ gst_amf_node_free (node2);
}
diff --git a/rtmp/amf.c b/rtmp/amf.c
index c15b74a..40fd2f1 100644
--- a/rtmp/amf.c
+++ b/rtmp/amf.c
@@ -79,7 +79,8 @@ gst_amf_node_free (GstAmfNode * node)
{
if (node->type == GST_AMF_TYPE_STRING) {
g_free (node->string_val);
- } else if (node->type == GST_AMF_TYPE_OBJECT) {
+ } else if (node->type == GST_AMF_TYPE_OBJECT ||
+ node->type == GST_AMF_TYPE_ECMA_ARRAY) {
g_ptr_array_foreach (node->array_val, (GFunc) amf_object_field_free, NULL);
g_ptr_array_free (node->array_val, TRUE);
}
@@ -174,10 +175,12 @@ _parse_object (AmfParser * parser, GstAmfNode * node)
s = _parse_utf8_string (parser);
child_node = _parse_value (parser);
if (child_node->type == GST_AMF_TYPE_OBJECT_END) {
+ g_free (s);
gst_amf_node_free (child_node);
break;
}
gst_amf_object_append_take (node, s, child_node);
+ g_free (s);
}
}
@@ -204,6 +207,7 @@ _parse_ecma_array (AmfParser * parser, GstAmfNode * node)
s = _parse_utf8_string (parser);
child_node = _parse_value (parser);
gst_amf_object_append_take (node, s, child_node);
+ g_free (s);
}
_parse_u24 (parser);
}
diff --git a/rtmp/rtmpchunk.c b/rtmp/rtmpchunk.c
index d2e623b..4dfbceb 100644
--- a/rtmp/rtmpchunk.c
+++ b/rtmp/rtmpchunk.c
@@ -118,6 +118,9 @@ gst_rtmp_chunk_finalize (GObject * object)
GST_DEBUG_OBJECT (rtmpchunk, "finalize");
/* clean up object here */
+ if (rtmpchunk->payload) {
+ g_bytes_unref (rtmpchunk->payload);
+ }
G_OBJECT_CLASS (gst_rtmp_chunk_parent_class)->finalize (object);
}
@@ -254,22 +257,13 @@ gst_rtmp_chunk_serialize (GstRtmpChunk * chunk,
data[7] = chunk->message_type_id;
offset = 8;
}
- /* FIXME this is probably all message types */
- if (chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_DATA ||
- chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_VIDEO ||
- chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_COMMAND) {
- for (i = 0; i < chunksize; i += max_chunk_size) {
- if (i != 0) {
- data[offset] = 0xc0 | chunk->chunk_stream_id;
- offset++;
- }
- memcpy (data + offset, chunkdata + i, MIN (chunksize - i,
- max_chunk_size));
- offset += MIN (chunksize - i, max_chunk_size);
+ for (i = 0; i < chunksize; i += max_chunk_size) {
+ if (i != 0) {
+ data[offset] = 0xc0 | chunk->chunk_stream_id;
+ offset++;
}
- } else {
- memcpy (data + offset, chunkdata, chunksize);
- offset += chunksize;
+ memcpy (data + offset, chunkdata + i, MIN (chunksize - i, max_chunk_size));
+ offset += MIN (chunksize - i, max_chunk_size);
}
GST_DEBUG ("type: %d in: %" G_GSIZE_FORMAT " out: %d", chunk->message_type_id,
chunksize, offset);
diff --git a/rtmp/rtmpclient.c b/rtmp/rtmpclient.c
index ed7c0d1..120e9a0 100644
--- a/rtmp/rtmpclient.c
+++ b/rtmp/rtmpclient.c
@@ -236,6 +236,7 @@ gst_rtmp_client_connect_async (GstRtmpClient * client,
GST_DEBUG ("g_socket_client_connect_async");
g_socket_client_connect_async (client->socket_client, addr,
client->cancellable, gst_rtmp_client_connect_done, client);
+ g_object_unref (addr);
}
static void
diff --git a/rtmp/rtmpconnection.c b/rtmp/rtmpconnection.c
index 46828de..88d2e20 100644
--- a/rtmp/rtmpconnection.c
+++ b/rtmp/rtmpconnection.c
@@ -259,17 +259,20 @@ gst_rtmp_connection_input_ready (GInputStream * is, gpointer user_data)
if (ret < 0) {
if (error->code == G_IO_ERROR_TIMED_OUT) {
/* should retry */
- GST_ERROR ("timeout, continuing");
+ GST_DEBUG ("timeout, continuing");
+ g_free (data);
g_error_free (error);
return G_SOURCE_CONTINUE;
} else {
GST_ERROR ("read error: %s %d %s", g_quark_to_string (error->domain),
error->code, error->message);
}
+ g_free (data);
g_error_free (error);
return G_SOURCE_REMOVE;
}
if (ret == 0) {
+ g_free (data);
gst_rtmp_connection_got_closed (sc);
return G_SOURCE_REMOVE;
}
@@ -330,7 +333,6 @@ gst_rtmp_connection_output_ready (GOutputStream * os, gpointer user_data)
sc->output_bytes =
gst_rtmp_chunk_serialize (chunk, &entry->previous_header,
sc->out_chunk_size);
- g_bytes_ref (sc->output_bytes);
gst_rtmp_chunk_cache_update (entry, chunk);
}
@@ -547,14 +549,7 @@ gst_rtmp_connection_chunk_callback (GstRtmpConnection * sc)
}
remaining_bytes = header.message_length - entry->offset;
- /* FIXME this is probably all message types */
- if (header.message_type_id == GST_RTMP_MESSAGE_TYPE_DATA ||
- header.message_type_id == GST_RTMP_MESSAGE_TYPE_VIDEO ||
- header.message_type_id == GST_RTMP_MESSAGE_TYPE_COMMAND) {
- chunk_bytes = MIN (remaining_bytes, sc->in_chunk_size);
- } else {
- chunk_bytes = remaining_bytes;
- }
+ chunk_bytes = MIN (remaining_bytes, sc->in_chunk_size);
data = g_bytes_get_data (sc->input_bytes, &size);
if (header.header_size + chunk_bytes > size) {
@@ -629,12 +624,12 @@ gst_rtmp_connection_handle_chunk (GstRtmpConnection * sc, GstRtmpChunk * chunk)
sc->command_callbacks = g_list_remove (sc->command_callbacks, cb);
cb->func (sc, chunk, command_name, transaction_id, command_object,
optional_args, cb->user_data);
- g_free (command_name);
- gst_amf_node_free (command_object);
- if (optional_args)
- gst_amf_node_free (optional_args);
g_free (cb);
}
+ g_free (command_name);
+ gst_amf_node_free (command_object);
+ if (optional_args)
+ gst_amf_node_free (optional_args);
}
GST_DEBUG ("got chunk: %" G_GSIZE_FORMAT " bytes", chunk->message_length);
g_signal_emit_by_name (sc, "got-chunk", chunk);
@@ -814,6 +809,7 @@ gst_rtmp_connection_client_handshake1 (GstRtmpConnection * sc)
g_output_stream_write_bytes_async (os, bytes,
G_PRIORITY_DEFAULT, sc->cancellable,
gst_rtmp_connection_client_handshake1_done, sc);
+ g_bytes_unref (bytes);
}
static void
@@ -853,6 +849,7 @@ gst_rtmp_connection_client_handshake2 (GstRtmpConnection * sc)
os = g_io_stream_get_output_stream (G_IO_STREAM (sc->connection));
g_output_stream_write_bytes_async (os, out_bytes, G_PRIORITY_DEFAULT,
sc->cancellable, gst_rtmp_connection_client_handshake2_done, sc);
+ g_bytes_unref (out_bytes);
}
static void
diff --git a/rtmp/rtmputils.c b/rtmp/rtmputils.c
index 54a0354..6f8fabd 100644
--- a/rtmp/rtmputils.c
+++ b/rtmp/rtmputils.c
@@ -211,7 +211,7 @@ gst_rtmp_dump_chunk (GstRtmpChunk * chunk, gboolean dir, gboolean dump_message,
chunk->message_length, chunk->message_type_id, chunk->stream_id);
if (dump_message) {
if (chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_COMMAND ||
- GST_RTMP_MESSAGE_TYPE_DATA) {
+ chunk->message_type_id == GST_RTMP_MESSAGE_TYPE_DATA) {
dump_command (chunk);
}
}