Hi Martin,

On 18 June 2010 10:57, Martin Storsjö <[email protected]> wrote:
> On Fri, 18 Jun 2010, Josh Allmann wrote:
>
>> On 18 June 2010 00:45, Martin Storsjö <[email protected]> wrote:
>> > Hi,
>> >
>> > I noticed that the GET URLContext can be leaked if some of the later
>> > operations fail before assigning the handles to rt->rtsp_hd{,_out}. This
>> > patch should fix the issue.
>> >
>> > Josh, do you think this is ok, or would you rather assign the handles
>> > directly to rt->rtsp_hd without using the local variables?
>> >
>>
>> Doesn't the jump to fail: clean things up? If I'm missing something
>> here, then it looks OK.
>
> Applied this fix, feel free to propose other ways to reorganize it to make
> it cleaner (e.g. by assigning the handles directly to rt->rtsp_hd, so the
> normal cleanup path can take care of it.

Thanks for the fix. I do agree that getting rid of the local variables
leads to cleaner code overall, so here's a patch for that.

Josh

>
> // Martin
> _______________________________________________
> FFmpeg-soc mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
>
>
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 6507841..d77485d 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1490,7 +1490,6 @@ int ff_rtsp_connect(AVFormatContext *s)
     RTSPState *rt = s->priv_data;
     char host[1024], path[1024], tcpname[1024], cmd[2048], auth[128];
     char *option_list, *option, *filename;
-    URLContext *rtsp_hd, *rtsp_hd_out;
     int port, err, tcp_fd;
     RTSPMessageHeader reply1 = {}, *reply = &reply1;
     int lower_transport_mask = 0;
@@ -1578,7 +1577,7 @@ redirect:
                  av_get_random_seed(), av_get_random_seed());
 
         /* GET requests */
-        if (url_open(&rtsp_hd, httpname, URL_RDONLY) < 0) {
+        if (url_open(&rt->rtsp_hd, httpname, URL_RDONLY) < 0) {
             err = AVERROR(EIO);
             goto fail;
         }
@@ -1590,18 +1589,16 @@ redirect:
                  "Pragma: no-cache\r\n"
                  "Cache-Control: no-cache\r\n",
                  sessioncookie);
-        ff_http_set_headers(rtsp_hd, headers);
+        ff_http_set_headers(rt->rtsp_hd, headers);
 
         /* complete the connection */
-        if (url_read(rtsp_hd, NULL, 0)) {
-            url_close(rtsp_hd);
+        if (url_read(rt->rtsp_hd, NULL, 0)) {
             err = AVERROR(EIO);
             goto fail;
         }
 
         /* POST requests */
-        if (url_open(&rtsp_hd_out, httpname, URL_WRONLY) < 0 ) {
-            url_close(rtsp_hd);
+        if (url_open(&rt->rtsp_hd_out, httpname, URL_WRONLY) < 0 ) {
             err = AVERROR(EIO);
             goto fail;
         }
@@ -1615,23 +1612,21 @@ redirect:
                  "Content-Length: 32767\r\n"
                  "Expires: Sun, 9 Jan 1972 00:00:00 GMT\r\n",
                  sessioncookie);
-        ff_http_set_headers(rtsp_hd_out, headers);
-        ff_http_set_chunked_transfer_encoding(rtsp_hd_out, 0);
+        ff_http_set_headers(rt->rtsp_hd_out, headers);
+        ff_http_set_chunked_transfer_encoding(rt->rtsp_hd_out, 0);
 
     } else {
         /* open the tcp connection */
         ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
-        if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) {
+        if (url_open(&rt->rtsp_hd, tcpname, URL_RDWR) < 0) {
             err = AVERROR(EIO);
             goto fail;
         }
-        rtsp_hd_out = rtsp_hd;
+        rt->rtsp_hd_out = rt->rtsp_hd;
     }
-    rt->rtsp_hd = rtsp_hd;
-    rt->rtsp_hd_out = rtsp_hd_out;
     rt->seq = 0;
 
-    tcp_fd = url_get_file_handle(rtsp_hd);
+    tcp_fd = url_get_file_handle(rt->rtsp_hd);
     if (!getpeername(tcp_fd, (struct sockaddr*) &peer, &peer_len)) {
         getnameinfo((struct sockaddr*) &peer, peer_len, host, sizeof(host),
                     NULL, 0, NI_NUMERICHOST);
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to