ffserver.c:562: error: Resource Leak
  resource acquired to `return` by call to `socket_open_listen()` at line 554, column 21 is not released after line 562, column 13.

ffserver.c:541:1: start of procedure http_server()
539. 
540. /* main loop of the http server */
541. static int http_server(void)
     ^
542. {
543.     int server_fd = 0, rtsp_server_fd = 0;

ffserver.c:543:5: 
541. static int http_server(void)
542. {
543.     int server_fd = 0, rtsp_server_fd = 0;
         ^
544.     int ret, delay, delay1;
545.     struct pollfd *poll_table, *poll_entry;

ffserver.c:548:10: 
546.     HTTPContext *c, *c_next;
547. 
548.     if(!(poll_table = av_mallocz((nb_max_http_connections + 2)*sizeof(*poll_table)))) {
              ^
549.         http_log("Impossible to allocate a poll table handling %d connections.\n", nb_max_http_connections);
550.         return -1;

libavutil/mem.c:132:1: start of procedure av_mallocz()
  130. }
  131. 
  132. void *av_mallocz(unsigned int size)
       ^
  133. {
  134.     void *ptr = av_malloc(size);

libavutil/mem.c:134:5: 
  132. void *av_mallocz(unsigned int size)
  133. {
  134.     void *ptr = av_malloc(size);
           ^
  135.     if (ptr)
  136.         memset(ptr, 0, size);

libavutil/mem.c:42:1: start of procedure av_malloc()
    40.    linker will do it automatically */
    41. 
    42. void *av_malloc(unsigned int size)
        ^
    43. {
    44.     void *ptr;

libavutil/mem.c:50:8: Taking false branch
    48. 
    49.     /* let's disallow possible ambiguous cases */
    50.     if(size > (INT_MAX-16) )
               ^
    51.         return NULL;
    52. 

libavutil/mem.c:61:5: Skipping memalign(): method has no implementation
    59.     ((char*)ptr)[-1]= diff;
    60. #elif defined (HAVE_MEMALIGN)
    61.     ptr = memalign(16,size);
            ^
    62.     /* Why 64?
    63.        Indeed, we should align it:

libavutil/mem.c:91:5: 
    89.     ptr = malloc(size);
    90. #endif
    91.     return ptr;
            ^
    92. }
    93. 

libavutil/mem.c:92:1: return from a call to av_malloc
    90. #endif
    91.     return ptr;
    92. }
        ^
    93. 
    94. void *av_realloc(void *ptr, unsigned int size)

libavutil/mem.c:135:9: Taking true branch
  133. {
  134.     void *ptr = av_malloc(size);
  135.     if (ptr)
               ^
  136.         memset(ptr, 0, size);
  137.     return ptr;

libavutil/mem.c:136:9: 
  134.     void *ptr = av_malloc(size);
  135.     if (ptr)
  136.         memset(ptr, 0, size);
               ^
  137.     return ptr;
  138. }

libavutil/mem.c:137:5: 
  135.     if (ptr)
  136.         memset(ptr, 0, size);
  137.     return ptr;
           ^
  138. }
  139. 

libavutil/mem.c:138:1: return from a call to av_mallocz
  136.         memset(ptr, 0, size);
  137.     return ptr;
  138. }
       ^
  139. 
  140. char *av_strdup(const char *s)

ffserver.c:548:10: Taking false branch
546.     HTTPContext *c, *c_next;
547. 
548.     if(!(poll_table = av_mallocz((nb_max_http_connections + 2)*sizeof(*poll_table)))) {
              ^
549.         http_log("Impossible to allocate a poll table handling %d connections.\n", nb_max_http_connections);
550.         return -1;

ffserver.c:553:9: Taking true branch
551.     }
552. 
553.     if (my_http_addr.sin_port) {
             ^
554.         server_fd = socket_open_listen(&my_http_addr);
555.         if (server_fd < 0)

ffserver.c:554:9: 
552. 
553.     if (my_http_addr.sin_port) {
554.         server_fd = socket_open_listen(&my_http_addr);
             ^
555.         if (server_fd < 0)
556.             return -1;

ffserver.c:454:1: start of procedure socket_open_listen()
  452. 
  453. /* open a listening socket */
  454. static int socket_open_listen(struct sockaddr_in *my_addr)
       ^
  455. {
  456.     int server_fd, tmp;

ffserver.c:458:5: 
  456.     int server_fd, tmp;
  457. 
  458.     server_fd = socket(AF_INET,SOCK_STREAM,0);
           ^
  459.     if (server_fd < 0) {
  460.         perror ("socket");

ffserver.c:459:9: Taking false branch
  457. 
  458.     server_fd = socket(AF_INET,SOCK_STREAM,0);
  459.     if (server_fd < 0) {
               ^
  460.         perror ("socket");
  461.         return -1;

ffserver.c:464:5: 
  462.     }
  463. 
  464.     tmp = 1;
           ^
  465.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
  466. 

ffserver.c:465:5: Skipping setsockopt(): method has no implementation
  463. 
  464.     tmp = 1;
  465.     setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
           ^
  466. 
  467.     if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {

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

ffserver.c:475:9: Taking false branch
  473.     }
  474. 
  475.     if (listen (server_fd, 5) < 0) {
               ^
  476.         perror ("listen");
  477.         closesocket(server_fd);

ffserver.c:480:5: 
  478.         return -1;
  479.     }
  480.     ff_socket_nonblock(server_fd, 1);
           ^
  481. 
  482.     return server_fd;

libavformat/os_support.c:77:1: start of procedure ff_socket_nonblock()
    75. }
    76. 
    77. int ff_socket_nonblock(int socket, int enable)
        ^
    78. {
    79. #ifdef HAVE_WINSOCK2_H

libavformat/os_support.c:82:8: Taking true branch
    80.    return ioctlsocket(socket, FIONBIO, &enable);
    81. #else
    82.    if (enable)
               ^
    83.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
    84.    else

libavformat/os_support.c:83:7: 
    81. #else
    82.    if (enable)
    83.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
              ^
    84.    else
    85.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);

libavformat/os_support.c:87:1: return from a call to ff_socket_nonblock
    85.       return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
    86. #endif
    87. }
        ^
    88. #endif /* CONFIG_NETWORK */
    89. 

ffserver.c:482:5: 
  480.     ff_socket_nonblock(server_fd, 1);
  481. 
  482.     return server_fd;
           ^
  483. }
  484. 

ffserver.c:483:1: return from a call to socket_open_listen
  481. 
  482.     return server_fd;
  483. }
       ^
  484. 
  485. /* start all multicast streams */

ffserver.c:555:13: Taking false branch
553.     if (my_http_addr.sin_port) {
554.         server_fd = socket_open_listen(&my_http_addr);
555.         if (server_fd < 0)
                 ^
556.             return -1;
557.     }

ffserver.c:559:9: Taking true branch
557.     }
558. 
559.     if (my_rtsp_addr.sin_port) {
             ^
560.         rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
561.         if (rtsp_server_fd < 0)

ffserver.c:560:9: 
558. 
559.     if (my_rtsp_addr.sin_port) {
560.         rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
             ^
561.         if (rtsp_server_fd < 0)
562.             return -1;

ffserver.c:454:1: start of procedure socket_open_listen()
  452. 
  453. /* open a listening socket */
  454. static int socket_open_listen(struct sockaddr_in *my_addr)
       ^
  455. {
  456.     int server_fd, tmp;

ffserver.c:458:5: 
  456.     int server_fd, tmp;
  457. 
  458.     server_fd = socket(AF_INET,SOCK_STREAM,0);
           ^
  459.     if (server_fd < 0) {
  460.         perror ("socket");

ffserver.c:459:9: Taking true branch
  457. 
  458.     server_fd = socket(AF_INET,SOCK_STREAM,0);
  459.     if (server_fd < 0) {
               ^
  460.         perror ("socket");
  461.         return -1;

ffserver.c:460:9: 
  458.     server_fd = socket(AF_INET,SOCK_STREAM,0);
  459.     if (server_fd < 0) {
  460.         perror ("socket");
               ^
  461.         return -1;
  462.     }

ffserver.c:461:9: 
  459.     if (server_fd < 0) {
  460.         perror ("socket");
  461.         return -1;
               ^
  462.     }
  463. 

ffserver.c:483:1: return from a call to socket_open_listen
  481. 
  482.     return server_fd;
  483. }
       ^
  484. 
  485. /* start all multicast streams */

ffserver.c:561:13: Taking true branch
559.     if (my_rtsp_addr.sin_port) {
560.         rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
561.         if (rtsp_server_fd < 0)
                 ^
562.             return -1;
563.     }

ffserver.c:562:13: 
560.         rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
561.         if (rtsp_server_fd < 0)
562.             return -1;
                 ^
563.     }
564. 

static int http_server(void)
{
    int server_fd = 0, rtsp_server_fd = 0;
    int ret, delay, delay1;
    struct pollfd *poll_table, *poll_entry;
    HTTPContext *c, *c_next;
    if(!(poll_table = av_mallocz((nb_max_http_connections + 2)*sizeof(*poll_table)))) {
        http_log("Impossible to allocate a poll table handling %d connections.\n", nb_max_http_connections);
        return -1;
    }
    if (my_http_addr.sin_port) {
        server_fd = socket_open_listen(&my_http_addr);
        if (server_fd < 0)
            return -1;
    }
    if (my_rtsp_addr.sin_port) {
        rtsp_server_fd = socket_open_listen(&my_rtsp_addr);
        if (rtsp_server_fd < 0)
            return -1;
    }
    if (!rtsp_server_fd && !server_fd) {
        http_log("HTTP and RTSP disabled.\n");
        return -1;
    }
    http_log("ffserver started.\n");
    start_children(first_feed);
    start_multicast();
    for(;;) {
        poll_entry = poll_table;
        if (server_fd) {
            poll_entry->fd = server_fd;
            poll_entry->events = POLLIN;
            poll_entry++;
        }
        if (rtsp_server_fd) {
            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 (server_fd) {
            if (poll_entry->revents & POLLIN)
                new_connection(server_fd, 0);
            poll_entry++;
        }
        if (rtsp_server_fd) {
            if (poll_entry->revents & POLLIN)
                new_connection(rtsp_server_fd, 1);
        }
    }
}
['static int http_server(void)\n{\n    int server_fd = 0, rtsp_server_fd = 0;\n    int ret, delay, delay1;\n    struct pollfd *poll_table, *poll_entry;\n    HTTPContext *c, *c_next;\n    if(!(poll_table = av_mallocz((nb_max_http_connections + 2)*sizeof(*poll_table)))) {\n        http_log("Impossible to allocate a poll table handling %d connections.\\n", nb_max_http_connections);\n        return -1;\n    }\n    if (my_http_addr.sin_port) {\n        server_fd = socket_open_listen(&my_http_addr);\n        if (server_fd < 0)\n            return -1;\n    }\n    if (my_rtsp_addr.sin_port) {\n        rtsp_server_fd = socket_open_listen(&my_rtsp_addr);\n        if (rtsp_server_fd < 0)\n            return -1;\n    }\n    if (!rtsp_server_fd && !server_fd) {\n        http_log("HTTP and RTSP disabled.\\n");\n        return -1;\n    }\n    http_log("ffserver started.\\n");\n    start_children(first_feed);\n    start_multicast();\n    for(;;) {\n        poll_entry = poll_table;\n        if (server_fd) {\n            poll_entry->fd = server_fd;\n            poll_entry->events = POLLIN;\n            poll_entry++;\n        }\n        if (rtsp_server_fd) {\n            poll_entry->fd = rtsp_server_fd;\n            poll_entry->events = POLLIN;\n            poll_entry++;\n        }\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 (server_fd) {\n            if (poll_entry->revents & POLLIN)\n                new_connection(server_fd, 0);\n            poll_entry++;\n        }\n        if (rtsp_server_fd) {\n            if (poll_entry->revents & POLLIN)\n                new_connection(rtsp_server_fd, 1);\n        }\n    }\n}', 'void *av_mallocz(unsigned int size)\n{\n    void *ptr = av_malloc(size);\n    if (ptr)\n        memset(ptr, 0, size);\n    return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n    void *ptr;\n#ifdef CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+16);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&15) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif defined (HAVE_MEMALIGN)\n    ptr = memalign(16,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\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}']