Obj-c, incorrect checksum for freed object - object was probably modified after being freed

☆樱花仙子☆ 提交于 2020-01-06 14:34:31

问题


I'm getting this error

malloc: * * * error for object 0x8a591d4: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
No memory available to program now: unsafe to call malloc
No memory available to program now: unsafe to call malloc

It comes from this line

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" 
       ofType:@"plist"];
NSData *plistData = [NSData dataWithContentsOfFile:plistPath];
NSDictionary *loadedPlist = 
[NSPropertyListSerialization  propertyListFromData:plistData 
       mutabilityOption:0 format:NULL errorDescription:NULL]; <<< this line

The value of plistData is set to Summary Unavailable

I'm not sure where to start ?

EDIT - added more code


回答1:


I'm going to add another answer: it's also possible that you have ALREADY hosed the heap, and you're failing on propertyListFromData: just because it does a lot of allocations and happens to hit the bad spot. So edit your scheme in Xcode, and make sure you have all of the Memory Management items checked (in the Diagnostics tab of the Run task).




回答2:


Have you set a breakpoint in malloc_error_break? This at least gives you a backtrace and you might see something of note. If nothing else, you could try po plistData from the GDB console.

BTW, while it may not help, I'd think dictionaryWithContentsOfFile: would be simpler.




回答3:


How is Info.plist being stored? Is it a standard plist/xml file? Would the following solve the problem you are trying to solve, and possibly prevent this issue from happening?

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" 
       ofType:@"plist"];
NSDictionary *loadedPlist = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

Or if you want an auto-released object...

NSDictionary *loadedPlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];


来源:https://stackoverflow.com/questions/8392106/obj-c-incorrect-checksum-for-freed-object-object-was-probably-modified-after

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!