Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory allocation if out of memory reboot issue #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ XTENSA_TOOLS_ROOT ?=
# base directory of the ESP8266 SDK package, absolute
# Only used for the non-FreeRTOS build
#SDK_BASE ?= /opt/Espressif/ESP8266_SDK
SDK_BASE ?= $(abspath ../esp_iot_sdk_v2.0.0.p1)
#SDK_BASE ?= $(abspath ../esp_iot_sdk_v2.0.0.p1)
SDK_BASE ?= $(abspath ../ESP8266_NONOS_SDK)

# Base directory of the ESP8266 FreeRTOS SDK package, absolute
# Only used for the FreeRTOS build
Expand Down
32 changes: 31 additions & 1 deletion core/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ void ICACHE_FLASH_ATTR httpdSentCb(ConnTypePtr rconn, char *remIp, int remPort)
if (conn->cgi==NULL) return;

sendBuff=malloc(MAX_SENDBUFF_LEN);
if (sendBuff == NULL)
{
httpd_printf("Send Buffer Out of Memory\n");
return;
}
conn->priv->sendBuff=sendBuff;
conn->priv->sendBuffLen=0;
conn->priv->sendBuffMax = MAX_SENDBUFF_LEN;
Expand Down Expand Up @@ -653,9 +658,16 @@ static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
void ICACHE_FLASH_ATTR httpdRecvCb(ConnTypePtr rconn, char *remIp, int remPort, char *data, unsigned short len) {
int x, r;
char *p, *e;
char *sendBuff=malloc(MAX_SENDBUFF_LEN);
char *sendBuff;

HttpdConnData *conn=rconn->reverse;
if (conn==NULL) return;
sendBuff = malloc(MAX_SENDBUFF_LEN);
if (sendBuff == NULL)
{
httpd_printf("Receive Call Back out of memory\n");
return;
}
conn->priv->sendBuff=sendBuff;
conn->priv->sendBuffLen=0;
conn->priv->sendBuffMax = MAX_SENDBUFF_LEN;
Expand Down Expand Up @@ -769,14 +781,32 @@ int ICACHE_FLASH_ATTR httpdConnectCb(ConnTypePtr conn, char *remIp, int remPort)
return 0;
}
connData[i]=malloc(sizeof(HttpdConnData));
if (connData[i] == NULL)
{
httpd_printf("Out of HTTP connection memory\n");
return 0;
}
memset(connData[i], 0, sizeof(HttpdConnData));
connData[i]->priv=malloc(sizeof(HttpdPriv));
if (connData[i]->priv == NULL)
{
httpd_printf("Out of HTTP Connection Memory 2\n");
free(connData[i]);
return 0;
}
memset(connData[i]->priv, 0, sizeof(HttpdPriv));
connData[i]->conn=conn;
conn->reverse = connData[i];
connData[i]->slot=i;
connData[i]->priv->headPos=0;
connData[i]->post=malloc(sizeof(HttpdPostData));
if (connData[i]->post == NULL)
{
httpd_printf("Out of HTTP Connection Memory 3\n");
free(connData[i]->priv);
free(connData[i]);
return 0;
}
memset(connData[i]->post, 0, sizeof(HttpdPostData));
connData[i]->post->buff=NULL;
connData[i]->post->buffLen=0;
Expand Down