LegacySupport: fix compile error for some devices am: c40b6510cb am: 3940f54aec
am: f13ef016c6

Change-Id: Ie88e89bc9ab287ccb1e19ce2b6c4c4eb18a8b0f1
diff --git a/transport/include/hidl/LegacySupport.h b/transport/include/hidl/LegacySupport.h
index 0f37ae0..7cb72a9 100644
--- a/transport/include/hidl/LegacySupport.h
+++ b/transport/include/hidl/LegacySupport.h
@@ -42,9 +42,10 @@
 
     LOG_FATAL_IF(service->isRemote(), "Implementation of %s/%s is remote!",
             Interface::descriptor, name.c_str());
-    LOG_FATAL_IF(ExpectInterface::castFrom(service) == nullptr,
-                 "Implementation of %s/%s is not a %s!", Interface::descriptor, name.c_str(),
-                 ExpectInterface::descriptor);
+
+    sp<ExpectInterface> expected = ExpectInterface::castFrom(service);
+    LOG_FATAL_IF(expected == nullptr, "Implementation of %s/%s is not a %s!", Interface::descriptor,
+                 name.c_str(), ExpectInterface::descriptor);
 
     status_t status = registerServiceCb(service, name);