From 3dae60ef47fcc74d3d9d5e7c866671f4fec1284d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 15 Jan 2013 16:24:33 -0600 Subject: [PATCH] cache: use rb_strdup() instead of a static buffer for cache lines. BUFSIZE limitation is retained as there is no need to remove it, as all lines must be smaller than it due to RFC1459 message requirements. --- include/cache.h | 3 +-- src/cache.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/cache.h b/include/cache.h index 4bf7ae51..d5396d39 100644 --- a/include/cache.h +++ b/include/cache.h @@ -4,7 +4,6 @@ #define HELP_MAX 100 -#define CACHELINELEN 81 #define CACHEFILELEN 30 /* two servernames, a gecos, three spaces, ":1", '\0' */ #define LINKSLINELEN (HOSTLEN + HOSTLEN + REALLEN + 6) @@ -23,7 +22,7 @@ struct cachefile struct cacheline { - char data[CACHELINELEN]; + char *data; rb_dlink_node linenode; }; diff --git a/src/cache.c b/src/cache.c index 3d7a5430..9941b330 100644 --- a/src/cache.c +++ b/src/cache.c @@ -62,8 +62,8 @@ init_cache(void) { /* allocate the emptyline */ emptyline = rb_malloc(sizeof(struct cacheline)); - emptyline->data[0] = ' '; - emptyline->data[1] = '\0'; + emptyline->data = rb_strdup(" "); + user_motd_changed[0] = '\0'; user_motd = cache_file(MPATH, "ircd.motd", 0); @@ -135,8 +135,13 @@ cache_file(const char *filename, const char *shortname, int flags) if(!EmptyString(line)) { + char untabline[BUFSIZE]; + lineptr = rb_malloc(sizeof(struct cacheline)); - untabify(lineptr->data, line, sizeof(lineptr->data)); + + untabify(untabline, line, sizeof(untabline)); + lineptr->data = rb_strdup(untabline); + rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents); } else @@ -209,7 +214,11 @@ free_cachefile(struct cachefile *cacheptr) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head) { if(ptr->data != emptyline) - rb_free(ptr->data); + { + struct cacheline *line = ptr->data; + rb_free(line->data); + rb_free(line); + } } rb_free(cacheptr);