diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-06-30 12:05:07 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-06-30 12:05:07 +0000 |
commit | ce945bd2f08f808ce76ba1a8b0026a3bcd9d45fb (patch) | |
tree | e94bcc495dffa188d2d3fbd1afcaee36bdab48cd | |
parent | 8efa6f407d18caae93a3fa3dd3760fc51cd46760 (diff) |
5K array on the stack is a big hefty, it is now allocated with malloc
instead
-rw-r--r-- | lib/cookie.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/cookie.c b/lib/cookie.c index 66309d767..8d8d100f0 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -638,17 +638,15 @@ struct CookieInfo *Curl_cookie_init(struct SessionHandle *data, struct CookieInfo *inc, bool newsession) { - char line[MAX_COOKIE_LINE]; struct CookieInfo *c; FILE *fp; bool fromfile=TRUE; if(NULL == inc) { /* we didn't get a struct, create one */ - c = (struct CookieInfo *)malloc(sizeof(struct CookieInfo)); + c = (struct CookieInfo *)calloc(1, sizeof(struct CookieInfo)); if(!c) return NULL; /* failed to get memory */ - memset(c, 0, sizeof(struct CookieInfo)); c->filename = strdup(file?file:"none"); /* copy the name just in case */ } else { @@ -669,20 +667,25 @@ struct CookieInfo *Curl_cookie_init(struct SessionHandle *data, if(fp) { char *lineptr; bool headerline; - while(fgets(line, MAX_COOKIE_LINE, fp)) { - if(checkprefix("Set-Cookie:", line)) { - /* This is a cookie line, get it! */ - lineptr=&line[11]; - headerline=TRUE; - } - else { - lineptr=line; - headerline=FALSE; - } - while(*lineptr && isspace((int)*lineptr)) - lineptr++; - Curl_cookie_add(data, c, headerline, lineptr, NULL, NULL); + char *line = (char *)malloc(MAX_COOKIE_LINE); + if(line) { + while(fgets(line, MAX_COOKIE_LINE, fp)) { + if(checkprefix("Set-Cookie:", line)) { + /* This is a cookie line, get it! */ + lineptr=&line[11]; + headerline=TRUE; + } + else { + lineptr=line; + headerline=FALSE; + } + while(*lineptr && isspace((int)*lineptr)) + lineptr++; + + Curl_cookie_add(data, c, headerline, lineptr, NULL, NULL); + } + free(line); /* free the line buffer */ } if(fromfile) fclose(fp); |