After some investigation, it looks like the crash is happening due to memory corruption, specifically of the messageDictionary object in the MPMessageBuilder class, but only when the withLocation: method is called. It seems that the pointer referenced invalid memory... It's unclear whether the root cause it in the SDK code or external code clobbering that memory, but in an attempt to resolve the issue I've refactored the MPMessageBuilder class in the following ways:
Make the messageDictionary object a (strong) property instead of an instance variable in case there's some kind of compiler issue preventing it from being properly strongly retained
Simplify class by removing the new class methods and just using init methods instead
Fixed incorrect marking of init methods as nonnull to nullable since they can return nil and in some cases explicitly do
Simplified other methods to no longer return self as it was not used much and hypothetically (though unlikely to impossible) the overwriting of the original reference could cause the memory to be released in between calling the methods and writing back over the reference. I don't think this is likely an actual issue but since we can't reproduce this problem I tried to change everything that could even remotely possibly cause a memory issue.
Testing Plan
[x] Was this tested locally? If not, explain why.
We have extensive tests against MPMessageBuilder and they are all still passing
Manually E2E tested to confirm messages were properly built and uploaded to the live stream
Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)
Summary
closes https://github.com/mParticle/mparticle-apple-sdk/issues/256
After some investigation, it looks like the crash is happening due to memory corruption, specifically of the
messageDictionary
object in theMPMessageBuilder
class, but only when thewithLocation:
method is called. It seems that the pointer referenced invalid memory... It's unclear whether the root cause it in the SDK code or external code clobbering that memory, but in an attempt to resolve the issue I've refactored theMPMessageBuilder
class in the following ways:messageDictionary
object a (strong) property instead of an instance variable in case there's some kind of compiler issue preventing it from being properly strongly retainednew
class methods and just using init methods insteadSimplified other methods to no longer return self as it was not used much and hypothetically (though unlikely to impossible) the overwriting of the original reference could cause the memory to be released in between calling the methods and writing back over the reference. I don't think this is likely an actual issue but since we can't reproduce this problem I tried to change everything that could even remotely possibly cause a memory issue.
Testing Plan
MPMessageBuilder
and they are all still passingReference Issue (For mParticle employees only. Ignore if you are an outside contributor)