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.
This commit is contained in:
William Pitcock 2013-01-15 16:24:33 -06:00
parent b6e02c25b5
commit 3dae60ef47
2 changed files with 14 additions and 6 deletions

View file

@ -4,7 +4,6 @@
#define HELP_MAX 100 #define HELP_MAX 100
#define CACHELINELEN 81
#define CACHEFILELEN 30 #define CACHEFILELEN 30
/* two servernames, a gecos, three spaces, ":1", '\0' */ /* two servernames, a gecos, three spaces, ":1", '\0' */
#define LINKSLINELEN (HOSTLEN + HOSTLEN + REALLEN + 6) #define LINKSLINELEN (HOSTLEN + HOSTLEN + REALLEN + 6)
@ -23,7 +22,7 @@ struct cachefile
struct cacheline struct cacheline
{ {
char data[CACHELINELEN]; char *data;
rb_dlink_node linenode; rb_dlink_node linenode;
}; };

View file

@ -62,8 +62,8 @@ init_cache(void)
{ {
/* allocate the emptyline */ /* allocate the emptyline */
emptyline = rb_malloc(sizeof(struct cacheline)); emptyline = rb_malloc(sizeof(struct cacheline));
emptyline->data[0] = ' '; emptyline->data = rb_strdup(" ");
emptyline->data[1] = '\0';
user_motd_changed[0] = '\0'; user_motd_changed[0] = '\0';
user_motd = cache_file(MPATH, "ircd.motd", 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)) if(!EmptyString(line))
{ {
char untabline[BUFSIZE];
lineptr = rb_malloc(sizeof(struct cacheline)); 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); rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
} }
else else
@ -209,7 +214,11 @@ free_cachefile(struct cachefile *cacheptr)
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
{ {
if(ptr->data != emptyline) if(ptr->data != emptyline)
rb_free(ptr->data); {
struct cacheline *line = ptr->data;
rb_free(line->data);
rb_free(line);
}
} }
rb_free(cacheptr); rb_free(cacheptr);