mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
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:
parent
b6e02c25b5
commit
3dae60ef47
2 changed files with 14 additions and 6 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
17
src/cache.c
17
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);
|
||||
|
|
Loading…
Reference in a new issue