gstreamer/ext/curl
Alex Ashley c2fe4e58ad curlhttpsrc: fix various leaks and thread safety issues
curlhttpsrc uses a single thread running the
gst_curl_http_src_curl_multi_loop() function to handle receiving
data and messages from libcurl. Each instance of curlhttpsrc adds
an entry into a queue in GstCurlHttpSrcMultiTaskContext and waits
for the multi_loop to perform the HTTP request.

Valgrind has shown up race conditions and memory leaks:
1. gst_curl_http_src_change_state() does not wait for the multi_loop
   to complete before going to the NULL state, which means that
   an instance of GstCurlHttpSrc can be released while
   gst_curl_http_src_curl_multi_loop() still has a reference to it.
2. if multiple elements try to be removed from the queue at once,
   only the last one is deleted.
3. source->caps is leaked
4. curl multi_handle is leaked
5. leak of curl_handle if URI not set
6. leak of http_headers when reusing element
7. null pointer dereference in negotiate caps
8. double-free of the default user-agent string
9. leak of multi_task_context.task

This commit changes the logic so that each element has a connection
status, which is used by the multi_loop to decide when to remove an
element from its queue. An instance of curlhttpsrc will not enter
the NULL state until its reference has been removed from the queue.

When shutting down the curl multi loop, the memory allocated from the
call to curl_multi_init() is now released.

When gstadaptivedemux uses a URI source element, it will re-use
it for multiple requests, moving it between READY and PLAYING
between each request. curlhttpsrc was leaking the http_headers
structure in this use case.

The gst_curl_http_src_negotiate_caps() function extracts the
"response-headers" field from the http_headers, but did not check
that this field might be NULL.

If the user-agent property is set, the global user-agent string
was freed. This caused a double-free error if the user-agent is
ever set a second time during the execution of the process.

There are situations within curlhttpsrc where the code needs
both the global multi_task_context mutex and the per-element
buffer_mutex. To avoid deadlocks, it is vital that the order in
which these are requested is always the same. This commit modifies
the locking order to always be in the order:
 1. multi_task_context.task_rec_mutex
 2. buffer_mutex

Fixes #876
2019-02-19 17:55:12 +00:00
..
curltask.h curlhttpsrc: Fix flagged Coverity errors 2017-07-26 23:16:10 +03:00
gstcurl.c curl: Add i18n 2017-11-21 16:30:17 +01:00
gstcurlbasesink.c curlbasesink: cleanup transfer immediately when done 2018-12-17 14:24:07 +00:00
gstcurlbasesink.h curlsink: handle socket callback for active FTP connections as well 2015-05-25 19:37:53 +01:00
gstcurldefaults.h curlhttpsrc: fix various leaks and thread safety issues 2019-02-19 17:55:12 +00:00
gstcurlfilesink.c docs: Port all docstring to gtk-doc markdown 2017-04-12 12:57:57 -03:00
gstcurlfilesink.h Fix FSF address 2012-11-04 00:09:59 +00:00
gstcurlftpsink.c docs: Port all docstring to gtk-doc markdown 2017-04-12 12:57:57 -03:00
gstcurlftpsink.h curl*sink: fix some gst-indent problems 2014-04-26 10:20:11 +02:00
gstcurlhttpsink.c curlhttpsink: free content type before assigning it 2018-12-17 15:56:08 +00:00
gstcurlhttpsink.h Fix FSF address 2012-11-04 00:09:59 +00:00
gstcurlhttpsrc.c curlhttpsrc: fix various leaks and thread safety issues 2019-02-19 17:55:12 +00:00
gstcurlhttpsrc.h curlhttpsrc: fix various leaks and thread safety issues 2019-02-19 17:55:12 +00:00
gstcurlqueue.c curlhttpsrc: fix various leaks and thread safety issues 2019-02-19 17:55:12 +00:00
gstcurlqueue.h curlhttpsrc: fix various leaks and thread safety issues 2019-02-19 17:55:12 +00:00
gstcurlsftpsink.c docs: Port all docstring to gtk-doc markdown 2017-04-12 12:57:57 -03:00
gstcurlsftpsink.h curl*sink: fix some gst-indent problems 2014-04-26 10:20:11 +02:00
gstcurlsmtpsink.c docs: Port all docstring to gtk-doc markdown 2017-04-12 12:57:57 -03:00
gstcurlsmtpsink.h curlsmtpsink: add final boundary to all multipart emails 2014-12-19 13:16:43 +00:00
gstcurlsshsink.c docs: Port all docstring to gtk-doc markdown 2017-04-12 12:57:57 -03:00
gstcurlsshsink.h curlsshsink: use the locally defined types 2014-10-26 21:04:02 +00:00
gstcurltlssink.c docs: Port all docstring to gtk-doc markdown 2017-04-12 12:57:57 -03:00
gstcurltlssink.h Fix FSF address 2012-11-04 00:09:59 +00:00
Makefile.am curl: Add curlhttpsrc element 2017-07-26 09:52:20 +03:00
meson.build meson: add 'curl-ssh2' option for curl libssh2 support 2018-10-28 11:53:42 +00:00