createBitmap的nativeColorSpaceCopy引发的abort 6 crash

问题

#00 pc 0001a7e4 /system/lib/libc.so (abort+63) [armeabi-v7a]
#01 pc 000065ab /system/lib/liblog.so (__android_log_assert+158) [armeabi-v7a]
#02 pc 000b59a9 /system/lib/libandroid_runtime.so [armeabi-v7a]
#03 pc 000b7321 /system/lib/libandroid_runtime.so (android::register_android_os_MessageQueue(_JNIEnv*)+92) [armeabi-v7a]
#04 pc 009dd5d9 /system/framework/arm/boot-framework.oat (oatexec+3962329) [armeabi]
android.graphics.Bitmap.createBitmap(Bitmap.java:905)
android.graphics.Bitmap.createScaledBitmap(Bitmap.java:754)

原因

在多线程环境中下载图片,通过Glide等引擎下载等bitmap有时候会有被复用的可能,尤其是使用同一url时,此时外部手动调用recycle()会造成此问题

简单排查

cat log.txt | grep createScaledBitmap -n 找出出现问题的关键字行
cat -n log.txt | tail -n +2950 | head -n 100 查看2950行后100行的内容
得到如下提示

  3058	12-10 15:24:31.173 18083 18699 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 18699 (MMT2 #8), pid 18083 (com.immomo.momo)
  3059	12-10 15:24:31.300 18845 18845 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
  3060	12-10 15:24:31.300 18845 18845 F DEBUG   : Build fingerprint: 'OPPO/PBEM00/PBEM00:8.1.0/OPM1.171019.026/1539153676:user/release-keys'
  3061	12-10 15:24:31.300 18845 18845 F DEBUG   : Revision: '0'
  3062	12-10 15:24:31.300 18845 18845 F DEBUG   : ABI: 'arm'
  3063	12-10 15:24:31.300 18845 18845 F DEBUG   : pid: 18083, tid: 18699, name: MMT2 #8  >>> com.immomo.momo <<<
  3064	12-10 15:24:31.300 18845 18845 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
  3065	12-10 15:24:31.306 18845 18845 F DEBUG   : Abort message: 'Error, cannot access an invalid/free'd bitmap here!'
  3066	12-10 15:24:31.306 18845 18845 F DEBUG   :     r0 00000000  r1 0000490b  r2 00000006  r3 00000008
  3067	12-10 15:24:31.306 18845 18845 F DEBUG   :     r4 000046a3  r5 0000490b  r6 becb4794  r7 0000010c
  3068	12-10 15:24:31.306 18845 18845 F DEBUG   :     r8 00000000  r9 c4573800  sl 13200690  fp 000002d0
  3069	12-10 15:24:31.306 18845 18845 F DEBUG   :     ip 00000000  sp becb4780  lr f146a933  pc f14647e4  cpsr 200e0030
  3070	12-10 15:24:31.615 18845 18845 F DEBUG   : 
  3071	12-10 15:24:31.615 18845 18845 F DEBUG   : backtrace:
  3072	12-10 15:24:31.615 18845 18845 F DEBUG   :     #00 pc 0001a7e4  /system/lib/libc.so (abort+63)
  3073	12-10 15:24:31.615 18845 18845 F DEBUG   :     #01 pc 000065ab  /system/lib/liblog.so (__android_log_assert+158)
  3074	12-10 15:24:31.615 18845 18845 F DEBUG   :     #02 pc 000c69a9  /system/lib/libandroid_runtime.so (android::BitmapWrapper::assertValid()+20)
  3075	12-10 15:24:31.615 18845 18845 F DEBUG   :     #03 pc 000c8321  /system/lib/libandroid_runtime.so (Bitmap_copyColorSpace(_JNIEnv*, _jobject*, long long, long long)+28)
  3076	12-10 15:24:31.615 18845 18845 F DEBUG   :     #04 pc 009dd5d9  /system/framework/arm/boot-framework.oat (offset 0x616000) (android.content.res.AssetManager.copyTheme [DEDUPED]+120)
  3077	12-10 15:24:31.615 18845 18845 F DEBUG   :     #05 pc 00a3faab  /system/framework/arm/boot-framework.oat (offset 0x616000) (android.graphics.Bitmap.createBitmap+1466)
  3078	12-10 15:24:31.615 18845 18845 F DEBUG   :     #06 pc 00a40bd9  /system/framework/arm/boot-framework.oat (offset 0x616000) (android.graphics.Bitmap.createScaledBitmap+368)

解决方案

’Error, cannot access an invalid/free’d bitmap here!’,debug后也发现是在nativeColorSpaceCopy这里出问题,因此不要手动recycle()可能之后被Glide等引擎使用的bitmap

你可能感兴趣的:(Android,bitmap,recycle)