diff options
| author | Nick White <git@njw.me.uk> | 2011-09-12 22:57:57 +0100 | 
|---|---|---|
| committer | Nick White <git@njw.me.uk> | 2011-09-12 22:57:57 +0100 | 
| commit | b8e6013ca1f59dd5f50c7e0ae07161f5c5fee25c (patch) | |
| tree | f62fb70713e623753c7e6fe06bdddb10d4619f80 | |
| parent | 45a96ef428c9808abcc6d4043f149eb6ac825ece (diff) | |
Only use memory for a page when needed
| -rw-r--r-- | TODO | 2 | ||||
| -rw-r--r-- | getgbook.c | 7 | 
2 files changed, 4 insertions, 5 deletions
@@ -16,7 +16,7 @@ bug in get(): if the \r\n\r\n after http headers is cut off between recv buffers  what happens if we receive not a http header? does recv loop forever, in a memory killing manner? -be more reasonable with memory: only allocate each page when it's processed, point to cookies rather than copy them +be more reasonable with memory: point to cookies rather than copy them  print stderr in gui as well @@ -45,10 +45,11 @@ int getpagelist()  	s+=strlen("_OC_Run({\"page\":[");  	for(i=0, p=pages[0];*s; s++) { -		p->url[0] = '\0';  		if(*s == ']')  			break;  		if(!strncmp(s, "\"pid\"", 5)) { +			p=pages[i++]=malloc(sizeof(**pages));; +			p->url[0] = '\0';  			snprintf(m, STRMAX, "\"%%%d[^\"]\"", STRMAX-1);  			sscanf(s+6, m, p->name);  			for(;*s; s++) { @@ -57,7 +58,6 @@ int getpagelist()  				if(!strncmp(s, "\"order\"", 7))  					sscanf(s+8, "%d,", &(p->num));  			} -			p=pages[++i];  		}  	} @@ -175,7 +175,6 @@ int main(int argc, char *argv[])  	bookid = argv[argc-1];  	pages = malloc(sizeof(*pages) * MAXPAGES); -	for(i=0; i<MAXPAGES; i++) pages[i] = malloc(sizeof(**pages));  	if(!(totalpages = getpagelist(bookid, pages))) {  		fprintf(stderr, "Could not find any pages for %s\n", bookid);  		return 1; @@ -220,7 +219,7 @@ int main(int argc, char *argv[])  		}  	} -	for(i=0; i<MAXPAGES; i++) free(pages[i]); +	for(i=0; i<totalpages; i++) free(pages[i]);  	free(pages);  	return EXIT_SUCCESS;  | 
