kernel 2.6.7 and Electric Fence

Zbyszek P. Karkuszewski zbyszek at drum.if.uj.edu.pl
Thu Oct 28 09:16:41 CEST 2004


Hi Guys,

I am writing this message in English because it might be of interest to a wider
linux community.

There is a strange behavior of Electric Fence 2.2.2 when applied to
a primitive C code (attached bellow). It returns the following error message:

ElectricFence Exiting: mprotect() failed: Cannot allocate memory

The program has been compiled with gcc-3.3.5; glibc version is 2.3.4;
kernel 2.6.7.

The same thing happens with older versions of these packages and on
several different hardware architectures. Size of the RAM is not an issue
here, it was way greater than a sufficient for the program + efence.

The troublesome line is 
	bm[i] = (double *)malloc((time_t)kmax*sizeof(double));
at i of order of 20k.

The author of efence, Bruce Perens, suspects some limitations of the linux
kernels.

Did you ever come across such limitations that could be responsible
for the error message above?

Here is the source code:

#define N 100  
#include<stdlib.h>

double **bm;
int main(){
    int i;
    long NN = 4*N*N;
    int kmax=100;
			    
	bm = (double **)malloc((time_t)NN*sizeof(double *));
	for(i=0; i<NN; ++i){
		bm[i] = (double*)malloc((time_t)kmax*sizeof(double));
	}

	for(i=0; i<NN; ++i){
		free(bm[i]);
	}
	free(bm);
	return 0;
}

I compile it with 
	gcc tmp.c -lefence



Cheers!
zbyszek




More information about the feedback mailing list