Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS bad access impossible to find

I'm stuck with a stupid bad access since so many hours. I'm totally unable to find it. I hope some of you will be able to show me the answer into the light. In the code bellow it appear on the line : NSString * stringCallVisit = [[NSString alloc]initWithFormat:..... I can't understand, all the objects are local of the method except the parameter theIntervention.

if i comment the method NSString * stringCallVisit = [[NSString alloc]initWithFormat:... the bad access don't appear even if i do id obj = callVisit.injectionby; instead of; So i suppose that the bad access is not from the callVisit object but certainly from the stringCallVisit object. But why i'm just instantiate it on the tine where the bad access appear.

Thanks for your help,

-(NSString*)getCallVisitForIntervention:(Intervention*)theIntervention
{

NSManagedObjectContext *context = [iPad_TestAppDelegate mainContext];
NSError *error;

NSFetchRequest *requestCallVisit = [[NSFetchRequest alloc]init];
[requestCallVisit setEntity:[NSEntityDescription entityForName:@"CallVisit" inManagedObjectContext:context]];

NSPredicate *predicateInterventionID = [NSPredicate predicateWithFormat:@"intervention_id = %@",theIntervention.id];
[requestCallVisit setPredicate:predicateInterventionID];        

NSMutableArray *callVisits = [[context executeFetchRequest:requestCallVisit error:&error]mutableCopy];



NSString *xml  = @"<CallVisits>";

for(CallVisit *callVisit in callVisits) 
{

    NSString * stringCallVisit = [[NSString alloc]initWithFormat:
                                  @"<CallVisit>"
                                  "<id>%@</id>"
                                  "<injectionby>%@</injectionby>"
                                  "<injectionspot>%@</injectionspot>"
                                  "<intervention_id>%@</intervention_id>"
                                  "<fls>%d</fls>"
                                  "<weight>%d</weight>"
                                  "<height>%d</height>"
                                  "<painAtInjection>%d</painAtInjection>"
                                  "<created>%@</created>"
                                  "<siteReaction>%d</siteReaction>"
                                  "<technicalComplain>%d</technicalComplain>"
                                  "<field1>%d</field1>"
                                  "<field2>%d</field2>"
                                  "<riskCompliance>%d</riskCompliance>"
                                  "<reasonCompliance>%@</reasonCompliance>"
                                  "<placebo>%@</placebo>"
                                  "<needlereceived>%@</needlereceived>"
                                  "<compliance>%d</compliance>"
                                  "<psychologicalCondition>%d</psychologicalCondition>"
                                  "<keepsegment>%d</keepsegment>"
                                  "</CallVisit>",
                                  callVisit.id,
                                  callVisit.injectionby,
                                  callVisit.injectionspot,
                                  callVisit.intervention_id,
                                  [callVisit.fls doubleValue],
                                  [callVisit.weight doubleValue],
                                  [callVisit.height doubleValue],
                                  [callVisit.painAtInjection intValue],
                                  callVisit.created,
                                  [callVisit.siteReaction intValue],
                                  [callVisit.technicalComplain intValue],
                                  [callVisit.field1 intValue],
                                  [callVisit.field2 intValue],
                                  [callVisit.riskCompliance intValue],
                                  callVisit.reasonCompliance,
                                  callVisit.placebo,
                                  callVisit.needlereceived,
                                  [callVisit.compliance intValue],
                                  [callVisit.psychologicalCondition intValue],
                                  [callVisit.keepsegment intValue]];



    xml = [xml stringByAppendingString:stringCallVisit];
    [stringCallVisit release];

    id obj = callVisit;

}       
[callVisits release];
[requestCallVisit release];

xml = [xml stringByAppendingString:@"</CallVisits>"];

return xml;
}

EDIT:

I did what you said but i'mm unable to understand the log and i don't received an adress to to the info malloc. I'm a bit lost :)

EDIT Here is the log. But it,s strange but know the app crash at an other place.

GuardMalloc[iPad Test-7405]: Failed to VM allocate 397648 bytes
GuardMalloc[iPad Test-7405]: Explicitly trapping into debugger!!!
sharedlibrary apply-load-rules all
Error in re-setting breakpoint 1:
Catchpoint 2 (throw)iPad Test(7405,0xaccab2c0) malloc: recording malloc stacks to disk using standard recorder
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
Error in re-setting breakpoint 1:
Error in re-setting breakpoint 1:
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Current language:  auto; currently objective-c
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
(gdb) 
like image 605
Amnysia Avatar asked Oct 20 '11 00:10

Amnysia


People also ask

What is Kern_invalid_address?

A memory leak occurs when memory is still allocated but nothing references it (or nothing references it usefully). A dangling pointer occurs when a pointer references memory that has been deallocated. EXC_BAD_ACCESS implies a dangling pointer, not the former. It could also imply an uninitialized pointer.

What does EXC_ BAD_ ACCESS mean Xcode?

What does EXC_BAD_ACCESS mean? EXC_BAD_ACCESS is an exception raised as a result of accessing bad memory. We're constantly working with pointers to memory in Swift that link to a specific memory address. An application will crash whenever we try to access a pointer that is invalid or no longer exists.

What does thread 1 Exc_bad_access mean?

EXC_BAD_ACCESS means that message was sent to a point in the memory where there's no instance of a class to execute it. Thus “bad access”. You will get EXC_BAD_ACCESS in 3 cases: An object is not initialized.


1 Answers

Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article for more detailed instructions.


Edit: It looks like you might be running out of memory. Do you have a didReceiveMemoryWarning method implemented? If so, put a NSLog in it to find out if you are lowon memory.

like image 86
chown Avatar answered Sep 18 '22 12:09

chown