2017-07-12 43 views
0

クラッシュスティックスの2つのスタックトレースがあります。どちらも同じコード行が含まれていますが、2つのクラッシュが発生します。iOS NSArrayのコピー時にクラッシュします。EXC_BAD_ACCESS KERN_PROTECTION_FAILURE

# OS Version: 10.3.2 (14F90) 
# Device: iPad 5 
# RAM Free: 3.8% 
# Disk Free: 90.7% 

#0. Crashed: com.apple.main-thread 
0 libsystem_platform.dylib  0x18d365090 _platform_memset + 126 
1 libsystem_malloc.dylib   0x18d2ebd00 _nano_malloc_check_clear + 584 
2 libsystem_malloc.dylib   0x18d2eacb0 nano_calloc + 80 
3 libsystem_malloc.dylib   0x18d2dc4e8 malloc_zone_calloc + 168 
4 libsystem_malloc.dylib   0x18d2dc41c calloc + 40 
5 libobjc.A.dylib    0x18cd18160 class_createInstance + 76 
6 CoreFoundation     0x18e2b2928 __CFAllocateObject + 28 
7 CoreFoundation     0x18e29c064 +[__NSSingleObjectArrayI __new::] + 28 
8 CoreFoundation     0x18e18cd18 -[NSArray initWithArray:range:copyItems:] + 400 
9 MyApp       0x10010003c -[ConstituentDownload currentProgress] (ConstituentDownload.m:117) 
10 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
11 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
12 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
13 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
14 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
15 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
16 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
17 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
18 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
19 MyApp       0x1001000b4 -[ConstituentDownload currentProgress] (ConstituentDownload.m:118) 
20 MyApp       0x100100234 -[ConstituentDownload sendProgressNotification] (ConstituentDownload.m:141) 
... button press stuff... 

と:

# OS Version: 10.3.1 (14E304) 
# Device: iPad 4 
# RAM Free: 4.7% 
# Disk Free: 12.2% 

#0. Crashed: com.apple.main-thread 
0 libobjc.A.dylib    0x1bc38692 objc_retain + 1 
1 CoreFoundation     0x1c8acf39 +[__NSArrayI __new:::] + 74 
2 CoreFoundation     0x1c8ae9f1 -[__NSArrayM copyWithZone:] + 174 
3 MyApp       0x189407 -[ConstituentDownload currentProgress] (ConstituentDownload.m:117) 
4 MyApp       0x18999f -[ConstituentDownload userInfoForProgressNotification] (ConstituentDownload.m:180) 
5 MyApp       0x189611 -[ConstituentDownload sendProgressNotification] (ConstituentDownload.m:144) 
...button press stuff... 

そして、ここでのクラッシュの原因となる方法は次のとおりです:

- (float)currentProgress { 

    float sections = [self.childDownloads count] + 1; 
    float referencedProgress = 0.; 
    // This line causes the crash - where we copy the property array 
    for(ConstituentDownload *d in [self.childDownloads copy]) { 
     referencedProgress += d.currentProgress; 
    } 
    float progress = (super.currentProgress + referencedProgress)/sections; 
    return progress; 
} 

self.childDownloadsは、この方法がに住んでいるのと同じタイプのオブジェクトを含むNSMutableArrayのですConstituentDownload。他のスレッドからアクセスされ、要素が追加されている可能性があります。そのため、反復処理を行う前に最初にコピーします。この配列は0〜20個のオブジェクトを含む傾向があります。

私はここにコピーしていますが、別のスレッドで配列を突然変異させることによってこのクラッシュが発生する可能性がありますか?

何らかの種類のメモリ破損が原因である可能性がありますか?もしそうなら、それを理解するために正しい方向に私を向けることができますか?

デバイスのRAMが不足している可能性がありますか?もしそうなら、なぜクラッシュレポートを生成するのではなく、メモリ不足エラーとして報告されていないのでしょうか?

はい、このメソッドはある意味で再帰的です。親のConstituentDownloadは、それぞれの子ダウンロードでcurrentProgressを呼び出し、子ダウンロードのそれぞれでそれを呼び出す。クラッシュスタックには1回の再帰呼び出ししかない場合があり、時には10回程度のクラッシュスタックがあります。

このクラッシュは、iOS 9とiOS 10を実行しているデバイスでのみ発生していますが、ほとんどのユーザーがこれらの2つのOSバージョンにある可能性があります。

とにかくKERN_PROTECTION_FAILUREは何を意味しますか?

答えて

1

正確に言及している特定のリファレンスが見つかりませんでしたが、このように可変配列をコピーすることは安全ではないと考えてください。

一般に、あるスレッドでNSMutableArrayを反復するのは安全ではありませんが、別のスレッドから突然変異しています。 copyがどんな方法で実装されていても、何らかの形で配列を反復処理してその作業を行う必要があります。

あなたの説明から、複数の異なるスレッドからアイテムを追加/削除しているようです。スレッドセーフなものにするために、ある種のロックやシリアル化を使用していますか?もしそうでなければ、クラッシュがこの時点で発生する可能性もあります。

この場合、同じロックを使用して、このcopy操作を保護する必要があります。

関連する問題