Added some extra checks for memory corruption (of course now that I

am looking, the problem is not happening).
This commit is contained in:
gardners 2012-02-15 23:51:12 +10:30
parent ce2afbe2ab
commit 3fed04e6cd
3 changed files with 25 additions and 4 deletions

View File

@ -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;

View File

@ -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");

View File

@ -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;