diff --git a/overlay.c b/overlay.c index ba9bb624..b1319b26 100644 --- a/overlay.c +++ b/overlay.c @@ -120,11 +120,11 @@ int overlayServerMode() /* Get rhizome server started BEFORE populating fd list so that the server's listen socket is in the list for poll() */ if (rhizome_datastore_path) rhizome_server_poll(); - + while(1) { /* Work out how long we can wait before we need to tick */ long long ms=overlay_time_until_next_tick(); - + memabuseCheck(); int filesPresent=0; fds[0].fd=sock; fds[0].events=POLLIN; fdcount=1; diff --git a/overlay_route.c b/overlay_route.c index 1b9eccc8..4c6f5fa6 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -245,9 +245,20 @@ overlay_neighbour *overlay_neighbours=NULL; int overlay_route_hash_order[16]; int overlay_route_hash_bytes=0; +int overlay_route_initP=0; int overlay_route_init(int mb_ram) { int i,j; + + /* Try to catch one observed behaviour when memory corruption has occurred. */ + if (overlay_route_initP) { + fprintf(stderr,"ERROR: overlay_route_init() multiply called.\n"); + sleep(3600); + } + overlay_route_initP=1; + + memabuseCheck(); + /* XXX Initialise the random number generator in a robust manner */ fprintf(stderr,"WARNING: RNG Not Securely Initialised.\n"); diff --git a/server.c b/server.c index 708a7ea6..7d5f5ace 100644 --- a/server.c +++ b/server.c @@ -663,16 +663,26 @@ int simpleServerMode() #ifdef DEBUG_MEM_ABUSE unsigned char groundzero[65536]; +int memabuseInitP=0; int memabuseInit() { + if (memabuseInitP) { + fprintf(stderr,"WARNING: memabuseInit() called more than once.\n"); + return memabuseCheck(); + } + unsigned char *zero=(unsigned char *)0; int i; - for(i=0;i<65536;i++) groundzero[i]=zero[i]; + for(i=0;i<65536;i++) { + groundzero[i]=zero[i]; + printf("%04x\n",i); + } + memabuseInitP=1; return 0; } -int memabuseCheck(char *func,char *file,int line) +int _memabuseCheck(const char *func,const char *file,const int line) { unsigned char *zero=(unsigned char *)0; int firstAddr=-1;