Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and enhance memory usage regarding log table #1783

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/chanprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ void tell_verbose_status(int idx)
"Threaded DNS core is disabled.\n"
#endif
"Socket table: %d/%d\n", threaddata()->MAXSOCKS, max_socks);
int j = 0;
int k = max_logs * sizeof(log_t);
for (int i = 0; i < max_logs; i++) {
if (logs[i].filename)
j++;
k += logs[i].szlast_len;
}
dprintf(idx, "Log table: %d/%d %d bytes\n", j, max_logs, k);
}

/* Show all internal state variables
Expand Down
10 changes: 9 additions & 1 deletion src/eggdrop.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,9 @@ typedef struct {
char *filename;
unsigned int mask; /* what to send to this log */
char *chname; /* which channel */
char szlast[LOGLINELEN]; /* for 'Last message repeated n times'
char *szlast; /* for 'Last message repeated n times'
* stuff in misc.c/putlog() <cybah> */
int szlast_len; /* sizeof szlast */
int repeats; /* number of times szLast has been repeated */
unsigned int flags; /* other flags <rtc> */
FILE *f; /* existing file */
Expand Down Expand Up @@ -734,6 +735,13 @@ enum {
# define STRINGIFY1(x) #x
#endif

#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif

#ifdef EGG_TDNS
#include <pthread.h>
#define DTN_TYPE_HOSTBYIP 0
Expand Down
33 changes: 17 additions & 16 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ int expmem_misc()
for (item = current->first; item; item = item->next)
tot += sizeof(struct help_list_t) + strlen(item->name) + 1;
}
for (int i = 0; i < max_logs; i++)
tot += logs[i].szlast_len;
return tot + (max_logs * sizeof(log_t));
}

Expand All @@ -95,20 +97,9 @@ void init_misc()

if (max_logs < 1)
max_logs = 1;
if (logs)
logs = nrealloc(logs, max_logs * sizeof(log_t));
else
logs = nmalloc(max_logs * sizeof(log_t));
for (; last < max_logs; last++) {
logs[last].filename = logs[last].chname = NULL;
logs[last].mask = 0;
logs[last].f = NULL;
/* Added by cybah */
logs[last].szlast[0] = 0;
logs[last].repeats = 0;
/* Added by rtc */
logs[last].flags = 0;
}
logs = nrealloc(logs, max_logs * sizeof(log_t));
memset(logs + last, 0, (max_logs - last) * sizeof(log_t));
last = max_logs;
}


Expand Down Expand Up @@ -587,7 +578,7 @@ void putlog (int type, char *chname, const char *format, ...)
/* Check if this is the same as the last line added to
* the log. <cybah>
*/
if (!strcasecmp(out + tsl, logs[i].szlast))
if (logs[i].szlast && !strcasecmp(out + tsl, logs[i].szlast))
/* It is a repeat, so increment repeats */
logs[i].repeats++;
else {
Expand All @@ -607,7 +598,17 @@ void putlog (int type, char *chname, const char *format, ...)
*/
}
fputs(out, logs[i].f);
strlcpy(logs[i].szlast, out + tsl, LOGLINEMAX);
size_t l = strlen(out + tsl);
if (l > logs[i].szlast_len) {
if (!logs[i].szlast_len) {
logs[i].szlast_len = MIN(MAX(l, 128), LOGLINELEN);
logs[i].szlast = nrealloc(logs[i].szlast, logs[i].szlast_len);
} else if (logs[i].szlast_len < LOGLINELEN) {
logs[i].szlast_len = MIN(MAX(l, logs[i].szlast_len << 1), LOGLINELEN);
logs[i].szlast = nrealloc(logs[i].szlast, logs[i].szlast_len);
}
}
strlcpy(logs[i].szlast, out + tsl, logs[i].szlast_len);
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/mod/server.mod/sasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,6 @@ static int gotauthenticate(char *from, char *msg)
char error_msg[1050]; /* snprintf() truncation should be tolerable */
int server_msg_plain_len;
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
char client_msg_b64[((MAX((sizeof client_msg_plain), 400) + 2) / 3) << 2] = "";

fixcolon(msg); /* Because Inspircd does its own thing */
Expand Down
Loading