fix memory leak

pull/30/head
Thorsten von Eicken 10 years ago
parent 657a16c75a
commit bb71b1f07e
  1. 5
      espfs/espfs.c
  2. 26
      httpd/httpd.c
  3. 5
      httpd/httpdespfs.c
  4. 2
      httpd/httpdespfs.h
  5. 4
      user/user_main.c

@ -47,7 +47,6 @@ It's written for use with httpd, but doesn't need to be used as such.
static char* espFsData = NULL; static char* espFsData = NULL;
struct EspFsFile { struct EspFsFile {
EspFsHeader *header; EspFsHeader *header;
char decompressor; char decompressor;
@ -147,7 +146,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
return NULL; return NULL;
} }
if (h.flags&FLAG_LASTFILE) { if (h.flags&FLAG_LASTFILE) {
os_printf("End of image.\n"); //os_printf("End of image.\n");
return NULL; return NULL;
} }
//Grab the name of the file. //Grab the name of the file.
@ -159,7 +158,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
//Yay, this is the file we need! //Yay, this is the file we need!
p+=h.nameLen; //Skip to content. p+=h.nameLen; //Skip to content.
r=(EspFsFile *)os_malloc(sizeof(EspFsFile)); //Alloc file desc mem r=(EspFsFile *)os_malloc(sizeof(EspFsFile)); //Alloc file desc mem
// os_printf("Alloc %p\n", r); //os_printf("Alloc %p[%d]\n", r, sizeof(EspFsFile));
if (r==NULL) return NULL; if (r==NULL) return NULL;
r->header=(EspFsHeader *)hpos; r->header=(EspFsHeader *)hpos;
r->decompressor=h.compression; r->decompressor=h.compression;

@ -118,16 +118,20 @@ static HttpdConnData ICACHE_FLASH_ATTR *httpdFindConnData(void *arg) {
//Retires a connection for re-use //Retires a connection for re-use
static void ICACHE_FLASH_ATTR httpdRetireConn(HttpdConnData *conn) { static void ICACHE_FLASH_ATTR httpdRetireConn(HttpdConnData *conn) {
conn->conn = NULL; // don't try to send anything, the SDK crashes...
if (conn->cgi != NULL) conn->cgi(conn); // free cgi data
if (conn->post->buff != NULL) {
os_free(conn->post->buff);
}
conn->cgi=NULL;
conn->post->buff=NULL;
conn->remote_port = 0;
conn->remote_ip[0] = 0;
uint32 dt = conn->startTime; uint32 dt = conn->startTime;
if (dt > 0) dt = (system_get_time() - dt)/1000; if (dt > 0) dt = (system_get_time() - dt)/1000;
os_printf("%s Closed, %ums, heap=%ld\n", connStr, dt, os_printf("%s Closed, %ums, heap=%ld\n", connStr, dt,
(unsigned long)system_get_free_heap_size()); (unsigned long)system_get_free_heap_size());
if (conn->post->buff!=NULL) os_free(conn->post->buff);
conn->post->buff=NULL;
conn->cgi=NULL;
conn->conn=NULL;
conn->remote_port = 0;
conn->remote_ip[0] = 0;
} }
//Stupid li'l helper function that returns the value of a hex char. //Stupid li'l helper function that returns the value of a hex char.
@ -301,8 +305,7 @@ static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
if (conn->cgi==NULL) { //Marked for destruction? if (conn->cgi==NULL) { //Marked for destruction?
//os_printf("Closing 0x%p/0x%p->0x%p\n", arg, conn->conn, conn); //os_printf("Closing 0x%p/0x%p->0x%p\n", arg, conn->conn, conn);
espconn_disconnect(conn->conn); espconn_disconnect(conn->conn); // we will get a disconnect callback
//httpdRetireConn(conn); // can't call this, we will get a diconnect callback!
return; //No need to call xmitSendBuff. return; //No need to call xmitSendBuff.
} }
@ -514,19 +517,16 @@ static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
debugConn(arg, "httpdDisconCb"); debugConn(arg, "httpdDisconCb");
HttpdConnData *conn = httpdFindConnData(arg); HttpdConnData *conn = httpdFindConnData(arg);
if (conn == NULL) return; if (conn == NULL) return;
if (conn->cgi != NULL) conn->cgi(conn); // free cgi data
httpdRetireConn(conn); httpdRetireConn(conn);
} }
// Callback indicating a failure in the connection. "Recon" is probably intended in the sense // Callback indicating a failure in the connection. "Recon" is probably intended in the sense
// of "you need to reconnect". Sigh... // of "you need to reconnect". Sigh... Note that there is no DiconCb after ReconCb
static void ICACHE_FLASH_ATTR httpdReconCb(void *arg, sint8 err) { static void ICACHE_FLASH_ATTR httpdReconCb(void *arg, sint8 err) {
debugConn(arg, "httpdReconCb"); debugConn(arg, "httpdReconCb");
HttpdConnData *conn = httpdFindConnData(arg); HttpdConnData *conn = httpdFindConnData(arg);
os_printf("%s reset, err=%d\n", connStr, err); os_printf("%s ***** reset, err=%d\n", connStr, err);
if (conn == NULL) return; if (conn == NULL) return;
conn->conn = NULL; // don't tr to send anything, the SDK crashes...
if (conn->cgi != NULL) conn->cgi(conn); // free cgi data
httpdRetireConn(conn); httpdRetireConn(conn);
} }

@ -34,6 +34,8 @@ int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData) {
char acceptEncodingBuffer[64]; char acceptEncodingBuffer[64];
int isGzip; int isGzip;
//os_printf("cgiEspFsHook conn=%p conn->conn=%p file=%p\n", connData, connData->conn, file);
if (connData->conn==NULL) { if (connData->conn==NULL) {
//Connection aborted. Clean up. //Connection aborted. Clean up.
espFsClose(file); espFsClose(file);
@ -89,7 +91,7 @@ int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData) {
} }
} }
#if 0
//cgiEspFsHtml is a simple HTML file that gets prefixed by head.tpl //cgiEspFsHtml is a simple HTML file that gets prefixed by head.tpl
int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData) { int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData) {
EspFsFile *file = connData->cgiData; EspFsFile *file = connData->cgiData;
@ -160,6 +162,7 @@ error: // error response
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }
} }
#endif
#if 0 #if 0
//cgiEspFsTemplate can be used as a template. //cgiEspFsTemplate can be used as a template.

@ -5,6 +5,6 @@
int cgiEspFsHook(HttpdConnData *connData); int cgiEspFsHook(HttpdConnData *connData);
int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData); int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData);
int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData); //int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData);
#endif #endif

@ -94,6 +94,8 @@ HttpdBuiltInUrl builtInUrls[]={
}; };
#define SHOW_HEAP_USE
#ifdef SHOW_HEAP_USE #ifdef SHOW_HEAP_USE
static ETSTimer prHeapTimer; static ETSTimer prHeapTimer;
@ -146,7 +148,7 @@ void user_init(void) {
#ifdef SHOW_HEAP_USE #ifdef SHOW_HEAP_USE
os_timer_disarm(&prHeapTimer); os_timer_disarm(&prHeapTimer);
os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
os_timer_arm(&prHeapTimer, 3000, 1); os_timer_arm(&prHeapTimer, 10000, 1);
#endif #endif
struct rst_info *rst_info = system_get_rst_info(); struct rst_info *rst_info = system_get_rst_info();

Loading…
Cancel
Save