(iOS) Crash in +[GADMAdNetworkAdapter availableAdapterNames] when combined with GoogleAnalytics SDK

159 views
Skip to first unread message

Robin Hamilton-Pennell

unread,
May 7, 2014, 1:53:18 PM5/7/14
to google-adm...@googlegroups.com
I have been pursuing a crash in our applications (see attached stack trace). It does not occur 100% of the time, suggesting a race condition. Upon inspection, I determined that the +[GADMAdNetworkAdapter availableAdapterNames] method is using an outdated way to get a list of all the classes in the application (objc_getClassList). This function is not necessarily atomic in its usage. As an experiment, I have swapped out the implementation at runtime, before initializing the Google Analytics SDK, and it appears to fix the crash:

    IMP getClasses = imp_implementationWithBlock(^ NSSet * {

        static NSMutableSet *classNames = nil;

        static dispatch_once_t onceToken;

        

        dispatch_once(&onceToken, ^{

            classNames = [[NSMutableSet alloc] init];

            unsigned int count;

            __unsafe_unretained Class *classes = objc_copyClassList(&count);

            Protocol *p = NSProtocolFromString(@"GADMAdNetworkAdapter");

            

            for (int i = 0; i < count; i++) {

                Class c = classes[i];

                if (class_conformsToProtocol(c, p)) {

                    NSString *className = [NSString stringWithFormat:@"%s", class_getName(c)];

                    [classNames addObject:className];

                }

            }

        });

        

        return classNames;

    });

    

    Class GADMAdNetworkAdapterClass = NSClassFromString(@"GADMAdNetworkAdapter");

    Method method = class_getClassMethod(GADMAdNetworkAdapterClass, NSSelectorFromString(@"availableAdapterNames"));

    method_setImplementation(method, getClasses);



Where is the appropriate place for me to post this issue in order to get a fix implemented for this crash?
crashFix.m
trace.txt

Robin Hamilton-Pennell

unread,
May 7, 2014, 2:13:25 PM5/7/14
to google-adm...@googlegroups.com
We are using libGoogleAdMobsAds 6.8.0 and libGoogleAnalyticsServices version 3.06.

Eric Leichtenschlag

unread,
May 8, 2014, 8:30:27 PM5/8/14
to google-adm...@googlegroups.com
Hi Robin,

You've come to the right place. Thanks for the investigation - we're going to take your advice and start using objc_copyClassList in the next release after the recently released 6.9.2.

Thanks,
Eric
Reply all
Reply to author
Forward
0 new messages