Added some new pools to nsmalloc.
Updated nick and sstring to use nsmalloc.
Changed chanservdb to use nsmalloc instead of its previous similar thing.
Made the core free up the sstring memory when it exits, and also check for
any outstanding blocks in nsmalloc.
Sundry change to allow opers to override chanserv commands by default snuck
in too.
case QPRIV_CHANGEUSERFLAGS:
return (np && rup && IsOper(np) && UHasOperPriv(rup));
- default:
- return 0;
+ default: /* By default opers can override anything */
+ return (np && rup && IsOper(np) && UHasOperPriv(rup));
}
}
#include "../../lib/sstring.h"
#include "../../parser/parser.h"
#include "../../core/events.h"
+#include "../../core/nsmalloc.h"
#include <string.h>
#include <libpq-fe.h>
releaseauthnameext(chanservaext);
csdb_freestuff();
- csfreeall();
+ nsfreeall(POOL_CHANSERVDB);
}
void csdb_handlestats(int hooknum, void *arg) {
*/
#include "../chanserv.h"
+#include "../../core/nsmalloc.h"
+
#include <stdlib.h>
#define ALLOCUNIT 100
csfreenicklists=NULL;
csfreeregbans=NULL;
csfreeactiveusers=NULL;
- csmallocs=NULL;
-}
-
-void *csmalloc(size_t size) {
- void **mem;
-
- /* Get the requested memory, with one extra pointer at the beginning */
- mem=(void **)malloc(size+sizeof(void *));
-
- /* Set the first word to point at the last thing we got */
- *mem=csmallocs;
-
- /* Now set the "last chunk" pointer to the address of this one */
- csmallocs=(void *)mem;
-
- /* return the rest of the memory to the caller */
- return (void *)(mem+1);
-}
-
-/*
- * csfreeall():
- * Free all the memory we allocated for chanserv structures.
- */
-
-void csfreeall() {
- void *vp,**vh;
-
- vp=csmallocs;
-
- while (vp!=NULL) {
- vh=(void **)vp;
- vp=*vh;
- free ((void *)vh);
- }
}
regchan *getregchan() {
regchan *rcp;
if (csfreechans==NULL) {
- csfreechans=(regchan *)csmalloc(ALLOCUNIT*sizeof(regchan));
+ csfreechans=(regchan *)nsmalloc(POOL_CHANSERVDB,ALLOCUNIT*sizeof(regchan));
for (i=0;i<(ALLOCUNIT-1);i++) {
csfreechans[i].index=(chanindex *)&(csfreechans[i+1]);
}
reguser *rup;
if (csfreeusers==NULL) {
- csfreeusers=(reguser *)csmalloc(ALLOCUNIT*sizeof(reguser));
+ csfreeusers=(reguser *)nsmalloc(POOL_CHANSERVDB,ALLOCUNIT*sizeof(reguser));
for (i=0;i<(ALLOCUNIT-1);i++) {
csfreeusers[i].nextbyname=&(csfreeusers[i+1]);
}
regchanuser *rcup;
if (csfreechanusers==NULL) {
- csfreechanusers=(regchanuser *)csmalloc(ALLOCUNIT*sizeof(regchanuser));
+ csfreechanusers=(regchanuser *)nsmalloc(POOL_CHANSERVDB,ALLOCUNIT*sizeof(regchanuser));
for (i=0;i<(ALLOCUNIT-1);i++) {
csfreechanusers[i].nextbyuser=&(csfreechanusers[i+1]);
}
nicklist *nlp;
if (csfreenicklists==NULL) {
- csfreenicklists=(nicklist *)csmalloc(ALLOCUNIT*sizeof(nicklist));
+ csfreenicklists=(nicklist *)nsmalloc(POOL_CHANSERVDB,ALLOCUNIT*sizeof(nicklist));
for (i=0;i<(ALLOCUNIT-1);i++) {
csfreenicklists[i].next=&(csfreenicklists[i+1]);
}
regban *rbp;
if (csfreeregbans==NULL) {
- csfreeregbans=(regban *)csmalloc(ALLOCUNIT*sizeof(regban));
+ csfreeregbans=(regban *)nsmalloc(POOL_CHANSERVDB,ALLOCUNIT*sizeof(regban));
for (i=0;i<(ALLOCUNIT-1);i++) {
csfreeregbans[i].next=&(csfreeregbans[i+1]);
}
activeuser *aup;
if (csfreeactiveusers==NULL) {
- csfreeactiveusers=(activeuser *)csmalloc(ALLOCUNIT*sizeof(activeuser));
+ csfreeactiveusers=(activeuser *)nsmalloc(POOL_CHANSERVDB,ALLOCUNIT*sizeof(activeuser));
for (i=0;i<(ALLOCUNIT-1);i++) {
csfreeactiveusers[i].next=&(csfreeactiveusers[i+1]);
}
#include "modules.h"
#include "config.h"
#include "error.h"
+#include "nsmalloc.h"
#include <stdlib.h>
#include <stdio.h>
break;
}
}
+
+ nsfreeall(POOL_SSTRING);
+ nsexit();
}
/*
pools[poolid]=NULL;
}
+void nsexit() {
+ unsigned int i;
+
+ for (i=0;i<MAXPOOL;i++) {
+ if (pools[i]) {
+ Error("core",ERR_INFO,"nsmalloc: Blocks still allocated in pool #%d\n",i);
+ nsfreeall(i);
+ }
+ }
+}
+
void *nsmalloc(unsigned int poolid, size_t size);
void nsfree(unsigned int poolid, void *ptr);
void nsfreeall(unsigned int poolid);
+void nsexit(void);
#define MAXPOOL 100
#define POOL_CHANINDEX 1
#define POOL_BANS 2
#define POOL_CHANNEL 3
+#define POOL_NICK 4
+#define POOL_CHANSERVDB 5
+#define POOL_SSTRING 6
#include "sstring.h"
#include "../core/hooks.h"
+#include "../core/nsmalloc.h"
#include <stdio.h>
/* Allocate more RAM */
allocstruct++;
- structmem=(sstring *)malloc(SSTRING_STRUCTALLOC);
+ structmem=(sstring *)nsmalloc(POOL_SSTRING,SSTRING_STRUCTALLOC);
assert(structmem!=NULL);
structfree=SSTRING_STRUCTALLOC;
}
} else {
/* Grab some more string space */
allocstring++;
- stringmem=(char *)malloc(SSTRING_DATAALLOC);
+ stringmem=(char *)nsmalloc(POOL_SSTRING,SSTRING_DATAALLOC);
assert(stringmem!=NULL);
stringfree=SSTRING_DATAALLOC;
}
#include "../server/server.h"
#include "../parser/parser.h"
#include "../lib/version.h"
+#include "../core/nsmalloc.h"
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
iptree = patricia_new_tree(PATRICIA_MAXBITS);
}
+void _fini() {
+ nsfreeall(POOL_NICK);
+
+ /* Free the hooks */
+ deregisterhook(HOOK_SERVER_NEWSERVER,&handleserverchange);
+ deregisterhook(HOOK_SERVER_LOSTSERVER,&handleserverchange);
+ deregisterhook(HOOK_CORE_STATSREQUEST,&nickstats);
+
+ /* And our server handlers */
+ deregisterserverhandler("N",&handlenickmsg);
+ deregisterserverhandler("D",&handlekillmsg);
+ deregisterserverhandler("Q",&handlequitmsg);
+ deregisterserverhandler("M",&handleusermodemsg);
+ deregisterserverhandler("W",&handlewhoismsg);
+ deregisterserverhandler("AC",&handleaccountmsg);
+ deregisterserverhandler("R",&handlestatsmsg);
+}
+
/*
* This function handles servers appearing and disappearing.
* For a new server, the client table is allocated.
switch(hooknum) {
case HOOK_SERVER_NEWSERVER:
- servernicks[servernum]=(nick **)malloc((serverlist[servernum].maxusernum+1)*sizeof(nick **));
+ servernicks[servernum]=(nick **)nsmalloc(POOL_NICK,(serverlist[servernum].maxusernum+1)*sizeof(nick **));
memset(servernicks[servernum],0,(serverlist[servernum].maxusernum+1)*sizeof(nick **));
break;
/* nick/host/realname/authname allocator */
#include "nick.h"
+#include "../core/nsmalloc.h"
+
#include <assert.h>
#include <stdlib.h>
int i;
if (freenicks==NULL) {
- freenicks=(nick *)malloc(ALLOCUNIT*sizeof(nick));
+ freenicks=(nick *)nsmalloc(POOL_NICK,ALLOCUNIT*sizeof(nick));
for (i=0;i<(ALLOCUNIT-1);i++) {
freenicks[i].next=&(freenicks[i+1]);
}
int i;
if (freehosts==NULL) {
- freehosts=(host *)malloc(ALLOCUNIT*sizeof(host));
+ freehosts=(host *)nsmalloc(POOL_NICK,ALLOCUNIT*sizeof(host));
for (i=0;i<(ALLOCUNIT-1);i++) {
freehosts[i].next=&(freehosts[i+1]);
}