当前位置:网站首页>JNI uses asan to check memory leaks

JNI uses asan to check memory leaks

2022-07-07 23:33:00 halem100

background

If JVM Some molecular modules belong to C++ Written so, You need to check for memory leaks , Provided here ASAN To check this so

resolvent

1.asan install

asan need gcc 4.8 Support for the above versions , If the experimental machine gcc The version is not high enough , Manual installation required gcc4.8 Version above , If the machine cannot be networked , You can download it manually first gcc Source package , Then compile the source code

tar xvf gcc-4.9.0.tar.gz
cd gcc-4.9.0
sudo yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel
sudo ./configure --prefix=/usr/local/gcc-4.9.0 --enable-threads=posix --disable-checking --disable-multilib
sudo make
sudo make install

2. Service deployment and startup

a) Compiling band asan Of so

makefile modify :

CFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize=leak -static-libasan
LIBFLAG += -fsanitize=address -static-libasan

b) Preset environment variables

export ASAN_OPTIONS=detect_leaks=1:halt_on_error=0:handle_segv=0:log_path=/tmp/asan.log
export LD_PRELOAD=/usr/local/gcc-4.9.0/lib64/libasan.so
export LSAN_OPTIONS=exitcode=0

Then deploy normally .

3. Memory problem check

After the service starts and runs for several times ,top command , Find service process id,kill -2 <pid>, After the process exits , see /tmp/asan.log.<pid> file , Information about existing memory leaks

原网站

版权声明
本文为[halem100]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130558418067.html