Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMDB accidental crash [FMStatement close] Xcode14.2 FMDB 2.5 #843

Open
yyakun opened this issue Mar 31, 2023 · 7 comments
Open

FMDB accidental crash [FMStatement close] Xcode14.2 FMDB 2.5 #843

yyakun opened this issue Mar 31, 2023 · 7 comments

Comments

@yyakun
Copy link

yyakun commented Mar 31, 2023

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000006f666e81
Exception Codes: 0x0000000000000001, 0x000000006f666e81
VM Region Info: 0x6f666e81 is not in any region. Bytes before following region: 2494321023
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 10412c000-104ca4000 [ 11.5M] r-x/r-x SM=COW ...p/TestData
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [5811]

Triggered by Thread: 13

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x1cc4d8194 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x1cc4e9a08 mach_msg2_internal + 76
2 libsystem_kernel.dylib 0x1cc4e9c44 mach_msg_overwrite + 384
3 libsystem_kernel.dylib 0x1cc4d8688 mach_msg + 20
4 CoreFoundation 0x18f43bfc4 __CFRunLoopServiceMachPort + 156
5 CoreFoundation 0x18f43d174 __CFRunLoopRun + 1232
6 CoreFoundation 0x18f441b7c CFRunLoopRunSpecific + 584
7 GraphicsServices 0x1c8ef7984 GSEventRunModal + 160
8 UIKitCore 0x1966333c8 -[UIApplication _run] + 868
9 UIKitCore 0x196633040 UIApplicationMain + 312
10 TestData 0x104148f94 0x10412c000 + 118676
11 dyld 0x1b0dd0df0 start + 2096

Thread 1:
0 libsystem_pthread.dylib 0x1db1d9674 start_wqthread + 0

Thread 2:
0 libsystem_pthread.dylib 0x1db1d9674 start_wqthread + 0

Thread 3:
0 libsystem_pthread.dylib 0x1db1d9674 start_wqthread + 0

Thread 4 name: Dispatch queue: com.tencent.bugly.persistenceQueue (QOS: UTILITY)
Thread 4:
0 libsystem_kernel.dylib 0x1cc4dd798 __rmdir + 8
1 libsystem_kernel.dylib 0x1cc4dbd70 rmdir + 12
2 libremovefile.dylib 0x20093f90c __removefile_tree_walker + 784
3 libremovefile.dylib 0x20093fb18 removefile + 240
4 Foundation 0x18e7d030c -[NSFilesystemItemRemoveOperation main] + 276
5 Foundation 0x18e7d0090 NSOPERATION_IS_INVOKING_MAIN + 12
6 Foundation 0x18e794ef4 -[NSOperation start] + 684
7 Foundation 0x18e796868 -[NSFileManager removeItemAtPath:error:] + 44
8 TestData 0x1045603ec 0x10412c000 + 4408300
9 libdispatch.dylib 0x19b07a7c8 _dispatch_client_callout + 16
10 libdispatch.dylib 0x19b01b8f0 _dispatch_once_callout + 28
11 TestData 0x1045643ac 0x10412c000 + 4424620
12 TestData 0x10456426c 0x10412c000 + 4424300
13 TestData 0x104563880 0x10412c000 + 4421760
14 Foundation 0x18e7f93c4 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 16
15 Foundation 0x18e7d00fc -[NSBlockOperation main] + 100
16 Foundation 0x18e7d0090 NSOPERATION_IS_INVOKING_MAIN + 12
17 Foundation 0x18e794ef4 -[NSOperation start] + 684
18 Foundation 0x18e794c40 NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION + 12
19 Foundation 0x18e799d60 __NSOQSchedule_f + 168
20 libdispatch.dylib 0x19b079850 _dispatch_call_block_and_release + 24
21 libdispatch.dylib 0x19b07a7c8 _dispatch_client_callout + 16
22 libdispatch.dylib 0x19b01c9e4 _dispatch_continuation_pop$VARIANT$mp + 444
23 libdispatch.dylib 0x19b01c108 _dispatch_async_redirect_invoke + 588
24 libdispatch.dylib 0x19b029cd0 _dispatch_root_queue_drain + 340
25 libdispatch.dylib 0x19b02a4d0 _dispatch_worker_thread2 + 172
26 libsystem_pthread.dylib 0x1db1d9b14 _pthread_wqthread + 224
27 libsystem_pthread.dylib 0x1db1d967c start_wqthread + 8

Thread 5 name: com.apple.uikit.eventfetch-thread
Thread 5:
0 libsystem_kernel.dylib 0x1cc4d8194 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x1cc4e9a08 mach_msg2_internal + 76
2 libsystem_kernel.dylib 0x1cc4e9c44 mach_msg_overwrite + 384
3 libsystem_kernel.dylib 0x1cc4d8688 mach_msg + 20
4 CoreFoundation 0x18f43bfc4 __CFRunLoopServiceMachPort + 156
5 CoreFoundation 0x18f43d174 __CFRunLoopRun + 1232
6 CoreFoundation 0x18f441b7c CFRunLoopRunSpecific + 584
7 Foundation 0x18e79a428 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208
8 Foundation 0x18e79a324 -[NSRunLoop(NSRunLoop) runUntilDate:] + 60
9 UIKitCore 0x1967580e0 -[UIEventFetcher threadMain] + 424
10 Foundation 0x18e7b1f74 NSThread__start + 704
11 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
12 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 6 name: Dispatch queue: com.apple.root.default-qos
Thread 6:
0 libsystem_kernel.dylib 0x1cc4d8610 __semwait_signal + 8
1 libsystem_c.dylib 0x19b09f2e8 nanosleep + 216
2 libsystem_c.dylib 0x19b0b2ed4 sleep + 48
3 TestData 0x104573538 0x10412c000 + 4486456
4 libdispatch.dylib 0x19b079850 _dispatch_call_block_and_release + 24
5 libdispatch.dylib 0x19b07a7c8 _dispatch_client_callout + 16
6 libdispatch.dylib 0x19b01c688 _dispatch_queue_override_invoke + 724
7 libdispatch.dylib 0x19b029cd0 _dispatch_root_queue_drain + 340
8 libdispatch.dylib 0x19b02a4d0 _dispatch_worker_thread2 + 172
9 libsystem_pthread.dylib 0x1db1d9b14 _pthread_wqthread + 224
10 libsystem_pthread.dylib 0x1db1d967c start_wqthread + 8

Thread 7:
0 libsystem_pthread.dylib 0x1db1d9674 start_wqthread + 0

Thread 8:
0 libsystem_kernel.dylib 0x1cc4d8194 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x1cc4e9a08 mach_msg2_internal + 76
2 libsystem_kernel.dylib 0x1cc4e9c44 mach_msg_overwrite + 384
3 libsystem_kernel.dylib 0x1cc4d8688 mach_msg + 20
4 CoreFoundation 0x18f43bfc4 __CFRunLoopServiceMachPort + 156
5 CoreFoundation 0x18f43d174 __CFRunLoopRun + 1232
6 CoreFoundation 0x18f441b7c CFRunLoopRunSpecific + 584
7 TestData 0x10436b544 0x10412c000 + 2356548
8 Foundation 0x18e7b1f74 NSThread__start + 704
9 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
10 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 9 name: com.apple.NSURLConnectionLoader
Thread 9:
0 libsystem_kernel.dylib 0x1cc4d8194 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x1cc4e9a08 mach_msg2_internal + 76
2 libsystem_kernel.dylib 0x1cc4e9c44 mach_msg_overwrite + 384
3 libsystem_kernel.dylib 0x1cc4d8688 mach_msg + 20
4 CoreFoundation 0x18f43bfc4 __CFRunLoopServiceMachPort + 156
5 CoreFoundation 0x18f43d174 __CFRunLoopRun + 1232
6 CoreFoundation 0x18f441b7c CFRunLoopRunSpecific + 584
7 CFNetwork 0x1955390f8 0x19530a000 + 2289912
8 Foundation 0x18e7b1f74 NSThread__start + 704
9 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
10 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 10 name: com.apple.CFSocket.private
Thread 10:
0 libsystem_kernel.dylib 0x1cc4d8c5c __select + 8
1 CoreFoundation 0x18f488198 __CFSocketManager + 624
2 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
3 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 11 name: WebThread
Thread 11:
0 libsystem_kernel.dylib 0x1cc4d8194 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x1cc4e9a08 mach_msg2_internal + 76
2 libsystem_kernel.dylib 0x1cc4e9c44 mach_msg_overwrite + 384
3 libsystem_kernel.dylib 0x1cc4d8688 mach_msg + 20
4 CoreFoundation 0x18f43bfc4 __CFRunLoopServiceMachPort + 156
5 CoreFoundation 0x18f43d174 __CFRunLoopRun + 1232
6 CoreFoundation 0x18f441b7c CFRunLoopRunSpecific + 584
7 WebCore 0x1a40c98c4 RunWebThread(void*) + 776
8 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
9 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 12 name: com.apple.CFStream.LegacyThread
Thread 12:
0 libsystem_kernel.dylib 0x1cc4d8194 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x1cc4e9a08 mach_msg2_internal + 76
2 libsystem_kernel.dylib 0x1cc4e9c44 mach_msg_overwrite + 384
3 libsystem_kernel.dylib 0x1cc4d8688 mach_msg + 20
4 CoreFoundation 0x18f43bfc4 __CFRunLoopServiceMachPort + 156
5 CoreFoundation 0x18f43d174 __CFRunLoopRun + 1232
6 CoreFoundation 0x18f441b7c CFRunLoopRunSpecific + 584
7 CoreFoundation 0x18f4c2410 _legacyStreamRunLoop_workThread + 260
8 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
9 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 13 Crashed:
0 libsqlite3.dylib 0x1b5c5a384 sqlite3_finalize + 32
1 TestData -[FMStatement close] (FMDatabase.m:1404)
2 TestData -[FMStatement close] (FMDatabase.m:1404)
3 TestData -[FMStatement dealloc] (FMDatabase.m:1399)
4 CoreFoundation 0x18f4386ac RELEASE_OBJECTS_IN_THE_SET + 148
5 CoreFoundation 0x18f419764 -[_NSSetM dealloc] + 144
6 libobjc.A.dylib 0x18d80d9a4 AutoreleasePoolPage::releaseUntil(objc_object**) + 192
7 libobjc.A.dylib 0x18d810dac objc_autoreleasePoolPop + 252
8 libobjc.A.dylib 0x18d83612c objc_tls_direct_base<AutoreleasePoolPage*, (tls_key)3, AutoreleasePoolPage::HotPageDealloc>::dtor
(void*) + 164
9 libsystem_pthread.dylib 0x1db1dbb18 _pthread_tsd_cleanup + 616
10 libsystem_pthread.dylib 0x1db1de9c8 _pthread_exit + 80
11 libsystem_pthread.dylib 0x1db1dce30 pthread_exit + 56
12 Foundation 0x18e7b2000 +[NSThread exit] + 16
13 Foundation 0x18e7b1f80 NSThread__start + 716
14 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
15 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 14:
0 libsystem_malloc.dylib 0x1a1970b24 nanov2_allocate_outlined + 140
1 libsystem_malloc.dylib 0x1a1970ba8 nanov2_allocate_outlined + 272
2 CoreFoundation 0x18f3d30cc __NSDictionaryM_new + 216
3 Foundation 0x18e7ede88 newJSONObject + 1416
4 Foundation 0x18e7ee57c newJSONValue + 492
5 Foundation 0x18e7ee7a0 newJSONValue + 1040
6 Foundation 0x18e7edb34 newJSONObject + 564
7 Foundation 0x18e7ee57c newJSONValue + 492
8 Foundation 0x18e7ee7a0 newJSONValue + 1040
9 Foundation 0x18e7edb34 newJSONObject + 564
10 Foundation 0x18e7ee57c newJSONValue + 492
11 Foundation 0x18e7c7dac -[_NSJSONReader parseData:options:error:] + 1076
12 TestData 0x1041b54c0 0x10412c000 + 562368
13 Foundation 0x18e7b1f74 NSThread__start + 704
14 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
15 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 15 name: Dispatch queue: fmdb.<FMDatabaseQueue: 0x2831c3840>
Thread 15:
0 libsystem_platform.dylib 0x1db143bb0 _platform_memset + 128
1 libsqlite3.dylib 0x1b5c6160c 0x1b5c37000 + 173580
2 libsqlite3.dylib 0x1b5cf5f70 0x1b5c37000 + 782192
3 libsqlite3.dylib 0x1b5c5c0dc 0x1b5c37000 + 151772
4 libsqlite3.dylib 0x1b5c7c440 0x1b5c37000 + 283712
5 libsqlite3.dylib 0x1b5c7b198 sqlite3_step + 1300
6 TestData 0x104489ff0 0x10412c000 + 3530736
7 TestData 0x10448a1d0 0x10412c000 + 3531216
8 TestData 0x10425d9d4 0x10412c000 + 1251796
9 TestData 0x10448c75c 0x10412c000 + 3540828
10 libdispatch.dylib 0x19b07a7c8 _dispatch_client_callout + 16
11 libdispatch.dylib 0x19b027a78 _dispatch_lane_barrier_sync_invoke_and_complete + 52
12 TestData 0x10448c6f8 0x10412c000 + 3540728
13 TestData 0x10425c41c 0x10412c000 + 1246236
14 TestData 0x1041a69d4 0x10412c000 + 502228
15 Foundation 0x18e7b1f74 NSThread__start + 704
16 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
17 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

Thread 16:
0 libsystem_kernel.dylib 0x1cc4d8ef8 read + 8
1 Foundation 0x18e78d6c4 _NSReadFromFileDescriptorWithProgress + 188
2 Foundation 0x18e782400 _NSReadBytesFromFileWithExtendedAttributes + 816
3 Foundation 0x18e773788 -[NSData(NSData) initWithContentsOfFile:options:maxLength:error:] + 128
4 Foundation 0x18e7730a0 +[NSArray(NSArray) newWithContentsOf:immutable:] + 96
5 Foundation 0x18e7daef0 +[NSArray(NSArray) arrayWithContentsOfFile:] + 28
6 TestData 0x10433d33c 0x10412c000 + 2167612
7 Foundation 0x18e7b1f74 NSThread__start + 704
8 libsystem_pthread.dylib 0x1db1db060 _pthread_start + 116
9 libsystem_pthread.dylib 0x1db1d9688 thread_start + 8

@lzcuriosity
Copy link

lzcuriosity commented Mar 31, 2023 via email

@ccgus
Copy link
Owner

ccgus commented Mar 31, 2023

It's hard to say without more information.

@yyakun
Copy link
Author

yyakun commented Apr 3, 2023

hello,This is my code

dispatch_async(dispatch_get_global_queue(0, 0), ^{
   for (NSInteger i = 0; i < 300; i++) {
        FMDatabaseQueue *queue = [DatabaseUtil getDatabase];
        [dbQueue inDatabase:^(FMDatabase *db) {
            if (![db open]) {
                return;
            }
            FMResultSet *dataRs;
            for(NSInteger j = 0;j <10;j++){
                //delete
                [db executeUpdate:deleteSql];
                //select
                dataRs = [db executeQuery:selectSql];
                
                if([dataRs next]){
                    //update
                    [db executeQuery:updateSql];
                }else{
                    //insert
                    [db executeQuery:insertSql];
                }
            }
            [dataRs close];
            [db close];
        }];
   }
});

DatabaseUtil
static FMDatabaseQueue* dbQueue = nil;
+(FMDatabaseQueue *)getDatabase
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dbQueue = [[FMDatabaseQueue alloc] initWithPath:dbFilePath];
});
return dbQueue;
}

crash [FMDatabase executeUpdate:error:withArgumentsInArray:orDictionary:orVAList:] (FMDatabase.m:)

@ccgus
Copy link
Owner

ccgus commented Apr 3, 2023

There's a lot going on here that probably shouldn't be, or needs to be fixed.

First, you probably want to close your result set (dataRs) right after you're done with it, not outside the loop.

Second, you don't want to open and close the db, let the database queue handle that for you. It'll do that automatically.

Finally - your defining queue = [DatabaseUtil getDatabase];, but then using a var named dbQueue. I hope that's just a copy and paste error?

@yyakun
Copy link
Author

yyakun commented Apr 17, 2023

Thank you for your help

@yyakun
Copy link
Author

yyakun commented Apr 17, 2023

Using setShouldCacheStatements YES or NO for different SQL statements on the same FMDatabaseQueue will result in sqlite3_ Finalize (_statement) crash?

@ccgus
Copy link
Owner

ccgus commented Apr 17, 2023

It shouldn't, but if you have a case where it does, I'd love to see the example code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants