From b8e6013ca1f59dd5f50c7e0ae07161f5c5fee25c Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 12 Sep 2011 22:57:57 +0100 Subject: Only use memory for a page when needed --- TODO | 2 +- getgbook.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index c63ee9d..cb240b6 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/getgbook.c b/getgbook.c index 862d90c..f43abec 100644 --- a/getgbook.c +++ b/getgbook.c @@ -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