fix memory leak

pull/30/head
Thorsten von Eicken 10 years ago
parent 657a16c75a
commit bb71b1f07e
  1. 7
      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;
struct EspFsFile {
EspFsHeader *header;
char decompressor;
@ -147,7 +146,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
return NULL;
}
if (h.flags&FLAG_LASTFILE) {
os_printf("End of image.\n");
//os_printf("End of image.\n");
return NULL;
}
//Grab the name of the file.
@ -159,7 +158,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
//Yay, this is the file we need!
p+=h.nameLen; //Skip to content.
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;
r->header=(EspFsHeader *)hpos;
r->decompressor=h.compression;
@ -266,7 +265,7 @@ void ICACHE_FLASH_ATTR espFsClose(EspFsFile *fh) {
// os_printf("Freed %p\n", dec);
}
#endif
// os_printf("Freed %p\n", fh);
//os_printf("Freed %p\n", fh);
os_free(fh);
}

@ -118,16 +118,20 @@ static HttpdConnData ICACHE_FLASH_ATTR *httpdFindConnData(void *arg) {
//Retires a connection for re-use
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;
if (dt > 0) dt = (system_get_time() - dt)/1000;
os_printf("%s Closed, %ums, heap=%ld\n", connStr, dt,
(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.
@ -301,8 +305,7 @@ static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
if (conn->cgi==NULL) { //Marked for destruction?
//os_printf("Closing 0x%p/0x%p->0x%p\n", arg, conn->conn, conn);
espconn_disconnect(conn->conn);
//httpdRetireConn(conn); // can't call this, we will get a diconnect callback!
espconn_disconnect(conn->conn); // we will get a disconnect callback
return; //No need to call xmitSendBuff.
}
@ -514,19 +517,16 @@ static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
debugConn(arg, "httpdDisconCb");
HttpdConnData *conn = httpdFindConnData(arg);
if (conn == NULL) return;
if (conn->cgi != NULL) conn->cgi(conn); // free cgi data
httpdRetireConn(conn);
}
// 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) {
debugConn(arg, "httpdReconCb");
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;
conn->conn = NULL; // don't tr to send anything, the SDK crashes...
if (conn->cgi != NULL) conn->cgi(conn); // free cgi data
httpdRetireConn(conn);
}

@ -34,6 +34,8 @@ int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData) {
char acceptEncodingBuffer[64];
int isGzip;
//os_printf("cgiEspFsHook conn=%p conn->conn=%p file=%p\n", connData, connData->conn, file);
if (connData->conn==NULL) {
//Connection aborted. Clean up.
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
int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData) {
EspFsFile *file = connData->cgiData;
@ -160,6 +162,7 @@ error: // error response
return HTTPD_CGI_DONE;
}
}
#endif
#if 0
//cgiEspFsTemplate can be used as a template.

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

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

Loading…
Cancel
Save