]> jfr.im git - irc/quakenet/newserv.git/blobdiff - proxyscan/proxyscanalloc.c
merge
[irc/quakenet/newserv.git] / proxyscan / proxyscanalloc.c
index dee282a71cfb92ee652509c03a65a996797bd44d..b4baf78f1972e7c0874f106b9a43ed070c3fe216 100644 (file)
@@ -1,6 +1,7 @@
 /* proxyscanalloc.c */
 
 #include "proxyscan.h"
+#include "../core/nsmalloc.h"
 
 #include <stdlib.h>
 
@@ -10,36 +11,7 @@ scan *freescans;
 cachehost *freecachehosts;
 pendingscan *freependingscans;
 foundproxy *freefoundproxies;
-
-void *mallocs=NULL;
-
-void *smalloc(size_t size) {
-  void **mem;
-
-  /* Get the memory we want, with an extra four bytes for our pointer */
-  mem=(void **)malloc(size+sizeof(void *));
-
-  /* Set the first word to point at the last chunk we got */
-  *mem=mallocs;
-
-  /* Now set the "last chunk" pointer to the address of this one */
-  mallocs=(void *)mem;
-
-  /* Return the rest of the memory to the caller */
-  return (void *)(mem+1);
-}
-
-void sfreeall() {
-  void *vp,**vp2;
-  
-  vp=mallocs;
-
-  while (vp!=NULL) {
-    vp2=(void **)vp;
-    vp=*vp2;
-    free((void *)vp2);
-  }
-}
+extrascan *freeextrascans;
 
 scan *getscan() {
   int i;
@@ -47,7 +19,7 @@ scan *getscan() {
   
   if (freescans==NULL) {
     /* Eep.  Allocate more. */
-    freescans=(scan *)smalloc(ALLOCUNIT*sizeof(scan));
+    freescans=(scan *)nsmalloc(POOL_PROXYSCAN,ALLOCUNIT*sizeof(scan));
     for (i=0;i<(ALLOCUNIT-1);i++) {
       freescans[i].next=&(freescans[i+1]);
     }
@@ -70,7 +42,7 @@ cachehost *getcachehost() {
   cachehost *chp;
   
   if (freecachehosts==NULL) {
-    freecachehosts=(cachehost *)smalloc(ALLOCUNIT*sizeof(cachehost));
+    freecachehosts=(cachehost *)nsmalloc(POOL_PROXYSCAN,ALLOCUNIT*sizeof(cachehost));
     for (i=0;i<(ALLOCUNIT-1);i++) {
       freecachehosts[i].next=&(freecachehosts[i+1]);
     }
@@ -93,7 +65,7 @@ pendingscan *getpendingscan() {
   pendingscan *psp;
 
   if (!freependingscans) {
-    freependingscans=(pendingscan *)smalloc(ALLOCUNIT * sizeof(pendingscan));
+    freependingscans=(pendingscan *)nsmalloc(POOL_PROXYSCAN,ALLOCUNIT * sizeof(pendingscan));
     for (i=0;i<(ALLOCUNIT-1);i++)
       freependingscans[i].next = freependingscans+i+1;
     freependingscans[ALLOCUNIT-1].next=NULL;
@@ -115,7 +87,7 @@ foundproxy *getfoundproxy() {
   foundproxy *fpp;
 
   if (!freefoundproxies) {
-    freefoundproxies=(foundproxy *)smalloc(ALLOCUNIT * sizeof(foundproxy));
+    freefoundproxies=(foundproxy *)nsmalloc(POOL_PROXYSCAN,ALLOCUNIT * sizeof(foundproxy));
     for (i=0;i<(ALLOCUNIT-1);i++)
       freefoundproxies[i].next = freefoundproxies+i+1;
     freefoundproxies[ALLOCUNIT-1].next=NULL;
@@ -132,3 +104,26 @@ void freefoundproxy(foundproxy *fpp) {
   freefoundproxies=fpp;
 }
 
+extrascan *getextrascan() {
+  int i;
+  extrascan *esp;
+
+  if (freeextrascans==NULL) {
+    freeextrascans=(extrascan *)nsmalloc(POOL_PROXYSCAN,ALLOCUNIT*sizeof(extrascan));
+    for (i=0;i<(ALLOCUNIT-1);i++) {
+      freeextrascans[i].next=&(freeextrascans[i+1]);
+    }
+    freeextrascans[ALLOCUNIT-1].next=NULL;
+  }
+
+  esp=freeextrascans;
+  freeextrascans=esp->next;
+
+  return esp;
+}
+
+void freeextrascan(extrascan *esp) {
+  esp->next=freeextrascans;
+  freeextrascans=esp;
+}
+