ffserver.c:603: error: Resource Leak
  resource acquired to `return` by call to `socket_open_listen()` at line 520, column 17 is not released after line 603, column 17.

ffserver.c:514:1: start of procedure http_server()
512. 
513. /* main loop of the http server */
514. static int http_server(void)
     ^
515. {
516.     int server_fd, ret, rtsp_server_fd, delay, delay1;

ffserver.c:520:5: 
518.     HTTPContext *c, *c_next;
519. 
520.     server_fd = socket_open_listen(&my_http_addr);
         ^
521.     if (server_fd < 0)
522.         return -1;

ffserver.c:427:1: start of procedure socket_open_listen()
  425. 
  426. /* open a listening socket */
  427. static int socket_open_listen(struct sockaddr_in *my_addr)
       ^
  428. {
  429.     int server_fd, tmp;

ffserver.c:431:5: 
  429.     int server_fd, tmp;
  430. 
  431.     server_fd = socket(AF_INET,SOCK_STREAM,0);
           ^
  432.     if (server_fd < 0) {
  433.         perror ("socket");

ffserver.c:432:9: Taking false branch
  430. 
  431.     server_fd = socket(AF_INET,SOCK_STREAM,0);
  432.     if (server_fd < 0) {
               ^
  433.         perror ("socket");
  434.         return -1;

ffserver.c:437:5: 
  435.     }
  436. 
  437.     tmp = 1;
           ^
  438.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
  439. 

ffserver.c:438:5: Skipping setsockopt(): method has no implementation
  436. 
  437.     tmp = 1;
  438.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
           ^
  439. 
  440.     if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {

ffserver.c:440:9: Taking false branch
  438.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
  439. 
  440.     if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {
               ^
  441.         char bindmsg[32];
  442.         snprintf(bindmsg, sizeof(bindmsg), "bind(port %d)", ntohs(my_addr->sin_port));

ffserver.c:448:9: Taking false branch
  446.     }
  447. 
  448.     if (listen (server_fd, 5) < 0) {
               ^
  449.         perror ("listen");
  450.         closesocket(server_fd);

ffserver.c:453:5: 
  451.         return -1;
  452.     }
  453.     ff_socket_nonblock(server_fd, 1);
           ^
  454. 
  455.     return server_fd;

libavformat/os_support.c:72:1: start of procedure ff_socket_nonblock()
    70. }
    71. 
    72. int ff_socket_nonblock(int socket, int enable)
        ^
    73. {
    74. #ifdef HAVE_WINSOCK2_H

libavformat/os_support.c:77:8: Taking true branch
    75.    return ioctlsocket(socket, FIONBIO, &enable);
    76. #else
    77.    if (enable)
               ^
    78.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
    79.    else

libavformat/os_support.c:78:7: 
    76. #else
    77.    if (enable)
    78.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
              ^
    79.    else
    80.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);

libavformat/os_support.c:82:1: return from a call to ff_socket_nonblock
    80.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
    81. #endif
    82. }
        ^
    83. #endif /* CONFIG_NETWORK */
    84. 

ffserver.c:455:5: 
  453.     ff_socket_nonblock(server_fd, 1);
  454. 
  455.     return server_fd;
           ^
  456. }
  457. 

ffserver.c:456:1: return from a call to socket_open_listen
  454. 
  455.     return server_fd;
  456. }
       ^
  457. 
  458. /* start all multicast streams */

ffserver.c:521:9: Taking false branch
519. 
520.     server_fd = socket_open_listen(&my_http_addr);
521.     if (server_fd < 0)
             ^
522.         return -1;
523. 

ffserver.c:524:5: 
522.         return -1;
523. 
524.     rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
         ^
525.     if (rtsp_server_fd < 0)
526.         return -1;

ffserver.c:427:1: start of procedure socket_open_listen()
  425. 
  426. /* open a listening socket */
  427. static int socket_open_listen(struct sockaddr_in *my_addr)
       ^
  428. {
  429.     int server_fd, tmp;

ffserver.c:431:5: 
  429.     int server_fd, tmp;
  430. 
  431.     server_fd = socket(AF_INET,SOCK_STREAM,0);
           ^
  432.     if (server_fd < 0) {
  433.         perror ("socket");

ffserver.c:432:9: Taking false branch
  430. 
  431.     server_fd = socket(AF_INET,SOCK_STREAM,0);
  432.     if (server_fd < 0) {
               ^
  433.         perror ("socket");
  434.         return -1;

ffserver.c:437:5: 
  435.     }
  436. 
  437.     tmp = 1;
           ^
  438.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
  439. 

ffserver.c:438:5: Skipping setsockopt(): method has no implementation
  436. 
  437.     tmp = 1;
  438.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
           ^
  439. 
  440.     if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {

ffserver.c:440:9: Taking false branch
  438.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
  439. 
  440.     if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {
               ^
  441.         char bindmsg[32];
  442.         snprintf(bindmsg, sizeof(bindmsg), "bind(port %d)", ntohs(my_addr->sin_port));

ffserver.c:448:9: Taking false branch
  446.     }
  447. 
  448.     if (listen (server_fd, 5) < 0) {
               ^
  449.         perror ("listen");
  450.         closesocket(server_fd);

ffserver.c:453:5: 
  451.         return -1;
  452.     }
  453.     ff_socket_nonblock(server_fd, 1);
           ^
  454. 
  455.     return server_fd;

libavformat/os_support.c:72:1: start of procedure ff_socket_nonblock()
    70. }
    71. 
    72. int ff_socket_nonblock(int socket, int enable)
        ^
    73. {
    74. #ifdef HAVE_WINSOCK2_H

libavformat/os_support.c:77:8: Taking true branch
    75.    return ioctlsocket(socket, FIONBIO, &enable);
    76. #else
    77.    if (enable)
               ^
    78.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
    79.    else

libavformat/os_support.c:78:7: 
    76. #else
    77.    if (enable)
    78.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
              ^
    79.    else
    80.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);

libavformat/os_support.c:82:1: return from a call to ff_socket_nonblock
    80.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
    81. #endif
    82. }
        ^
    83. #endif /* CONFIG_NETWORK */
    84. 

ffserver.c:455:5: 
  453.     ff_socket_nonblock(server_fd, 1);
  454. 
  455.     return server_fd;
           ^
  456. }
  457. 

ffserver.c:456:1: return from a call to socket_open_listen
  454. 
  455.     return server_fd;
  456. }
       ^
  457. 
  458. /* start all multicast streams */

ffserver.c:525:9: Taking false branch
523. 
524.     rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
525.     if (rtsp_server_fd < 0)
             ^
526.         return -1;
527. 

ffserver.c:528:5: 
526.         return -1;
527. 
528.     http_log("ffserver started.\n");
         ^
529. 
530.     start_children(first_feed);

ffserver.c:308:1: start of procedure http_log()
  306. static FILE *logfile = NULL;
  307. 
  308. static void __attribute__ ((format (printf, 1, 2))) http_log(const char *fmt, ...)
       ^
  309. {
  310.     va_list ap;

ffserver.c:311:5: 
  309. {
  310.     va_list ap;
  311.     va_start(ap, fmt);
           ^
  312. 
  313.     if (logfile) {

ffserver.c:313:9: Taking true branch
  311.     va_start(ap, fmt);
  312. 
  313.     if (logfile) {
               ^
  314.         vfprintf(logfile, fmt, ap);
  315.         fflush(logfile);

ffserver.c:314:9: 
  312. 
  313.     if (logfile) {
  314.         vfprintf(logfile, fmt, ap);
               ^
  315.         fflush(logfile);
  316.     }

ffserver.c:315:9: 
  313.     if (logfile) {
  314.         vfprintf(logfile, fmt, ap);
  315.         fflush(logfile);
               ^
  316.     }
  317.     va_end(ap);

ffserver.c:317:5: 
  315.         fflush(logfile);
  316.     }
  317.     va_end(ap);
           ^
  318. }
  319. 

ffserver.c:318:1: return from a call to http_log
  316.     }
  317.     va_end(ap);
  318. }
       ^
  319. 
  320. static char *ctime1(char *buf2)

ffserver.c:530:5: Skipping start_children(): empty list of specs
528.     http_log("ffserver started.\n");
529. 
530.     start_children(first_feed);
         ^
531. 
532.     first_http_ctx = NULL;

ffserver.c:532:5: 
530.     start_children(first_feed);
531. 
532.     first_http_ctx = NULL;
         ^
533.     nb_connections = 0;
534. 

ffserver.c:533:5: 
531. 
532.     first_http_ctx = NULL;
533.     nb_connections = 0;
         ^
534. 
535.     start_multicast();

ffserver.c:535:5: Skipping start_multicast(): empty list of specs
533.     nb_connections = 0;
534. 
535.     start_multicast();
         ^
536. 
537.     for(;;) {

ffserver.c:631:5: Loop condition is true. Entering loop body
629.         if (poll_entry->revents & POLLIN)
630.             new_connection(rtsp_server_fd, 1);
631.     }
         ^
632. }
633. 

ffserver.c:538:9: 
536. 
537.     for(;;) {
538.         poll_entry = poll_table;
             ^
539.         poll_entry->fd = server_fd;
540.         poll_entry->events = POLLIN;

ffserver.c:539:9: 
537.     for(;;) {
538.         poll_entry = poll_table;
539.         poll_entry->fd = server_fd;
             ^
540.         poll_entry->events = POLLIN;
541.         poll_entry++;

ffserver.c:540:9: 
538.         poll_entry = poll_table;
539.         poll_entry->fd = server_fd;
540.         poll_entry->events = POLLIN;
             ^
541.         poll_entry++;
542. 

ffserver.c:541:9: 
539.         poll_entry->fd = server_fd;
540.         poll_entry->events = POLLIN;
541.         poll_entry++;
             ^
542. 
543.         poll_entry->fd = rtsp_server_fd;

ffserver.c:543:9: 
541.         poll_entry++;
542. 
543.         poll_entry->fd = rtsp_server_fd;
             ^
544.         poll_entry->events = POLLIN;
545.         poll_entry++;

ffserver.c:544:9: 
542. 
543.         poll_entry->fd = rtsp_server_fd;
544.         poll_entry->events = POLLIN;
             ^
545.         poll_entry++;
546. 

ffserver.c:545:9: 
543.         poll_entry->fd = rtsp_server_fd;
544.         poll_entry->events = POLLIN;
545.         poll_entry++;
             ^
546. 
547.         /* wait for events on each HTTP handle */

ffserver.c:548:9: 
546. 
547.         /* wait for events on each HTTP handle */
548.         c = first_http_ctx;
             ^
549.         delay = 1000;
550.         while (c != NULL) {

ffserver.c:549:9: 
547.         /* wait for events on each HTTP handle */
548.         c = first_http_ctx;
549.         delay = 1000;
             ^
550.         while (c != NULL) {
551.             int fd;

ffserver.c:550:16: Loop condition is false. Leaving loop
548.         c = first_http_ctx;
549.         delay = 1000;
550.         while (c != NULL) {
                    ^
551.             int fd;
552.             fd = c->fd;

ffserver.c:600:13: Skipping poll(): method has no implementation
598.            second to handle timeouts */
599.         do {
600.             ret = poll(poll_table, poll_entry - poll_table, delay);
                 ^
601.             if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
602.                 ff_neterrno() != FF_NETERROR(EINTR))

ffserver.c:601:17: Taking true branch
599.         do {
600.             ret = poll(poll_table, poll_entry - poll_table, delay);
601.             if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
                     ^
602.                 ff_neterrno() != FF_NETERROR(EINTR))
603.                 return -1;

ffserver.c:601:28: Taking true branch
599.         do {
600.             ret = poll(poll_table, poll_entry - poll_table, delay);
601.             if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
                                ^
602.                 ff_neterrno() != FF_NETERROR(EINTR))
603.                 return -1;

ffserver.c:602:17: Taking true branch
600.             ret = poll(poll_table, poll_entry - poll_table, delay);
601.             if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
602.                 ff_neterrno() != FF_NETERROR(EINTR))
                     ^
603.                 return -1;
604.         } while (ret < 0);

ffserver.c:603:17: 
601.             if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
602.                 ff_neterrno() != FF_NETERROR(EINTR))
603.                 return -1;
                     ^
604.         } while (ret < 0);
605. 

static int http_server(void)
{
    int server_fd, ret, rtsp_server_fd, delay, delay1;
    struct pollfd poll_table[HTTP_MAX_CONNECTIONS + 2], *poll_entry;
    HTTPContext *c, *c_next;
    server_fd = socket_open_listen(&my_http_addr);
    if (server_fd < 0)
        return -1;
    rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
    if (rtsp_server_fd < 0)
        return -1;
    http_log("ffserver started.\n");
    start_children(first_feed);
    first_http_ctx = NULL;
    nb_connections = 0;
    start_multicast();
    for(;;) {
        poll_entry = poll_table;
        poll_entry->fd = server_fd;
        poll_entry->events = POLLIN;
        poll_entry++;
        poll_entry->fd = rtsp_server_fd;
        poll_entry->events = POLLIN;
        poll_entry++;
        c = first_http_ctx;
        delay = 1000;
        while (c != NULL) {
            int fd;
            fd = c->fd;
            switch(c->state) {
            case HTTPSTATE_SEND_HEADER:
            case RTSPSTATE_SEND_REPLY:
            case RTSPSTATE_SEND_PACKET:
                c->poll_entry = poll_entry;
                poll_entry->fd = fd;
                poll_entry->events = POLLOUT;
                poll_entry++;
                break;
            case HTTPSTATE_SEND_DATA_HEADER:
            case HTTPSTATE_SEND_DATA:
            case HTTPSTATE_SEND_DATA_TRAILER:
                if (!c->is_packetized) {
                    c->poll_entry = poll_entry;
                    poll_entry->fd = fd;
                    poll_entry->events = POLLOUT;
                    poll_entry++;
                } else {
                    delay1 = 10;
                    if (delay1 < delay)
                        delay = delay1;
                }
                break;
            case HTTPSTATE_WAIT_REQUEST:
            case HTTPSTATE_RECEIVE_DATA:
            case HTTPSTATE_WAIT_FEED:
            case RTSPSTATE_WAIT_REQUEST:
                c->poll_entry = poll_entry;
                poll_entry->fd = fd;
                poll_entry->events = POLLIN;
                poll_entry++;
                break;
            default:
                c->poll_entry = NULL;
                break;
            }
            c = c->next;
        }
        do {
            ret = poll(poll_table, poll_entry - poll_table, delay);
            if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
                ff_neterrno() != FF_NETERROR(EINTR))
                return -1;
        } while (ret < 0);
        cur_time = av_gettime() / 1000;
        if (need_to_start_children) {
            need_to_start_children = 0;
            start_children(first_feed);
        }
        for(c = first_http_ctx; c != NULL; c = c_next) {
            c_next = c->next;
            if (handle_connection(c) < 0) {
                log_connection(c);
                close_connection(c);
            }
        }
        poll_entry = poll_table;
        if (poll_entry->revents & POLLIN)
            new_connection(server_fd, 0);
        poll_entry++;
        if (poll_entry->revents & POLLIN)
            new_connection(rtsp_server_fd, 1);
    }
}
['static int http_server(void)\n{\n    int server_fd, ret, rtsp_server_fd, delay, delay1;\n    struct pollfd poll_table[HTTP_MAX_CONNECTIONS + 2], *poll_entry;\n    HTTPContext *c, *c_next;\n    server_fd = socket_open_listen(&my_http_addr);\n    if (server_fd < 0)\n        return -1;\n    rtsp_server_fd = socket_open_listen(&my_rtsp_addr);\n    if (rtsp_server_fd < 0)\n        return -1;\n    http_log("ffserver started.\\n");\n    start_children(first_feed);\n    first_http_ctx = NULL;\n    nb_connections = 0;\n    start_multicast();\n    for(;;) {\n        poll_entry = poll_table;\n        poll_entry->fd = server_fd;\n        poll_entry->events = POLLIN;\n        poll_entry++;\n        poll_entry->fd = rtsp_server_fd;\n        poll_entry->events = POLLIN;\n        poll_entry++;\n        c = first_http_ctx;\n        delay = 1000;\n        while (c != NULL) {\n            int fd;\n            fd = c->fd;\n            switch(c->state) {\n            case HTTPSTATE_SEND_HEADER:\n            case RTSPSTATE_SEND_REPLY:\n            case RTSPSTATE_SEND_PACKET:\n                c->poll_entry = poll_entry;\n                poll_entry->fd = fd;\n                poll_entry->events = POLLOUT;\n                poll_entry++;\n                break;\n            case HTTPSTATE_SEND_DATA_HEADER:\n            case HTTPSTATE_SEND_DATA:\n            case HTTPSTATE_SEND_DATA_TRAILER:\n                if (!c->is_packetized) {\n                    c->poll_entry = poll_entry;\n                    poll_entry->fd = fd;\n                    poll_entry->events = POLLOUT;\n                    poll_entry++;\n                } else {\n                    delay1 = 10;\n                    if (delay1 < delay)\n                        delay = delay1;\n                }\n                break;\n            case HTTPSTATE_WAIT_REQUEST:\n            case HTTPSTATE_RECEIVE_DATA:\n            case HTTPSTATE_WAIT_FEED:\n            case RTSPSTATE_WAIT_REQUEST:\n                c->poll_entry = poll_entry;\n                poll_entry->fd = fd;\n                poll_entry->events = POLLIN;\n                poll_entry++;\n                break;\n            default:\n                c->poll_entry = NULL;\n                break;\n            }\n            c = c->next;\n        }\n        do {\n            ret = poll(poll_table, poll_entry - poll_table, delay);\n            if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&\n                ff_neterrno() != FF_NETERROR(EINTR))\n                return -1;\n        } while (ret < 0);\n        cur_time = av_gettime() / 1000;\n        if (need_to_start_children) {\n            need_to_start_children = 0;\n            start_children(first_feed);\n        }\n        for(c = first_http_ctx; c != NULL; c = c_next) {\n            c_next = c->next;\n            if (handle_connection(c) < 0) {\n                log_connection(c);\n                close_connection(c);\n            }\n        }\n        poll_entry = poll_table;\n        if (poll_entry->revents & POLLIN)\n            new_connection(server_fd, 0);\n        poll_entry++;\n        if (poll_entry->revents & POLLIN)\n            new_connection(rtsp_server_fd, 1);\n    }\n}', 'static int socket_open_listen(struct sockaddr_in *my_addr)\n{\n    int server_fd, tmp;\n    server_fd = socket(AF_INET,SOCK_STREAM,0);\n    if (server_fd < 0) {\n        perror ("socket");\n        return -1;\n    }\n    tmp = 1;\n    setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));\n    if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {\n        char bindmsg[32];\n        snprintf(bindmsg, sizeof(bindmsg), "bind(port %d)", ntohs(my_addr->sin_port));\n        perror (bindmsg);\n        closesocket(server_fd);\n        return -1;\n    }\n    if (listen (server_fd, 5) < 0) {\n        perror ("listen");\n        closesocket(server_fd);\n        return -1;\n    }\n    ff_socket_nonblock(server_fd, 1);\n    return server_fd;\n}', 'int ff_socket_nonblock(int socket, int enable)\n{\n#ifdef HAVE_WINSOCK2_H\n   return ioctlsocket(socket, FIONBIO, &enable);\n#else\n   if (enable)\n      return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);\n   else\n      return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);\n#endif\n}', 'static void __attribute__ ((format (printf, 1, 2))) http_log(const char *fmt, ...)\n{\n    va_list ap;\n    va_start(ap, fmt);\n    if (logfile) {\n        vfprintf(logfile, fmt, ap);\n        fflush(logfile);\n    }\n    va_end(ap);\n}']