{"action":"closed","issue":{"url":"https://api.github.com/repos/Spritetm/esphttpd-freertos/issues/1","repository_url":"https://api.github.com/repos/Spritetm/esphttpd-freertos","labels_url":"https://api.github.com/repos/Spritetm/esphttpd-freertos/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/Spritetm/esphttpd-freertos/issues/1/comments","events_url":"https://api.github.com/repos/Spritetm/esphttpd-freertos/issues/1/events","html_url":"https://github.com/Spritetm/esphttpd-freertos/issues/1","id":153347311,"number":1,"title":"Bug in platHttpServerTask","user":{"login":"jhinklejr","id":19215077,"avatar_url":"https://avatars.githubusercontent.com/u/19215077?v=3","gravatar_id":"","url":"https://api.github.com/users/jhinklejr","html_url":"https://github.com/jhinklejr","followers_url":"https://api.github.com/users/jhinklejr/followers","following_url":"https://api.github.com/users/jhinklejr/following{/other_user}","gists_url":"https://api.github.com/users/jhinklejr/gists{/gist_id}","starred_url":"https://api.github.com/users/jhinklejr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhinklejr/subscriptions","organizations_url":"https://api.github.com/users/jhinklejr/orgs","repos_url":"https://api.github.com/users/jhinklejr/repos","events_url":"https://api.github.com/users/jhinklejr/events{/privacy}","received_events_url":"https://api.github.com/users/jhinklejr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-05T23:18:45Z","updated_at":"2016-05-05T23:29:35Z","closed_at":"2016-05-05T23:29:35Z","body":"Function: static void platHttpServerTask(void *pvParameters) \r\n\r\ncode starting at line 192 ... I expanded it with spaces so you can see the bug\r\n\r\n\t\t\t\tif (FD_ISSET(rconn[x].fd, &readset))\r\n                                 {\r\n\t\t\t\t\tprecvbuf=(char*)malloc(RECV_BUF_SIZE);\r\n\t\t\t\t\tif (precvbuf==NULL)\r\n                                                                  httpd_printf(\"platHttpServerTask: memory exhausted!\\n\");\r\n\r\nBUG--> if malloc fails you still fall into rcv which will crash .... \r\n\r\n\t\t\t\t\tret=recv(rconn[x].fd, precvbuf, RECV_BUF_SIZE,0);\r\n\t\t\t\t\tif (ret > 0) {\r\n\t\t\t\t\t\t//Data received. Pass to httpd.\r\n\t\t\t\t\t\thttpdRecvCb(&rconn[x], rconn[x].ip, rconn[x].port, precvbuf, ret);\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\t//recv error,connection close\r\n\t\t\t\t\t\thttpdDisconCb(&rconn[x], rconn[x].ip, rconn[x].port);\r\n\t\t\t\t\t\tclose(rconn[x].fd);\r\n\t\t\t\t\t\trconn[x].fd=-1;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (precvbuf) free(precvbuf);\r\n\t\t\t\t}\r\n\r\n\r\nI'm not sure the best solution ... I was going to say \r\n\r\n                                if (precvbuf==NULL)\r\n                                {\r\n                                     httpd_printf(\"platHttpServerTask: memory exhausted!\\n\");\r\n                                     continue;\r\n                                 }\r\n\r\nbut that would just lead to an un-blocked select and the task would spin.\r\n\r\nI will probably process as if rcv failed - close socket and disconnect.\r\n\r\nPlease let me know what your thoughts are.\r\n\r\nJoe\r\n"}}