Skip to content

Commit

Permalink
Enhance memory usage regarding log table
Browse files Browse the repository at this point in the history
Add MIN() and MAX() to eggdrop.h
  • Loading branch information
michaelortmann committed Feb 20, 2025
1 parent 341477a commit 379d83a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
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
31 changes: 15 additions & 16 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,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 +576,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 +596,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/servmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,9 +1342,6 @@ static int tryauthenticate(char *from, char *msg)
char *s;
/* 400-byte chunk, see: https://ircv3.net/specs/extensions/sasl-3.1.html
* base64 padding */
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
unsigned char dst[((MAX((sizeof src), 400) + 2) / 3) << 2] = "";
#ifdef HAVE_EVP_PKEY_GET1_EC_KEY
int olen;
Expand Down

0 comments on commit 379d83a

Please sign in to comment.