OSDN Git Service

Fix memory leak warning.
authorYunlian Jiang <yunlian@google.com>
Tue, 27 Jun 2017 22:51:41 +0000 (15:51 -0700)
committerYunlian Jiang <yunlian@google.com>
Wed, 28 Jun 2017 18:34:08 +0000 (11:34 -0700)
This CL eliminates the following compiler warning:

MediaPlayerFactory.cpp:249:27: warning: Potential memory leak

Bug: None
Test: After this change the warning is gone.
Change-Id: I09e7ec5cc3bc84decfea2456550b532aac55d26f

media/libmediaplayerservice/MediaPlayerFactory.cpp

index 605c710..f7c691d 100644 (file)
@@ -246,8 +246,12 @@ void MediaPlayerFactory::registerBuiltinFactories() {
     if (sInitComplete)
         return;
 
-    registerFactory_l(new NuPlayerFactory(), NU_PLAYER);
-    registerFactory_l(new TestPlayerFactory(), TEST_PLAYER);
+    IFactory* factory = new NuPlayerFactory();
+    if (registerFactory_l(factory, NU_PLAYER) != OK)
+        delete factory;
+    factory = new TestPlayerFactory();
+    if (registerFactory_l(factory, TEST_PLAYER) != OK)
+        delete factory;
 
     sInitComplete = true;
 }