OSDN Git Service

Fix clang static analyzer warnings.
authorManoj Gupta <manojgupta@google.com>
Tue, 18 Jul 2017 22:57:14 +0000 (15:57 -0700)
committerManoj Gupta <manojgupta@google.com>
Tue, 18 Jul 2017 23:43:46 +0000 (16:43 -0700)
Fix the following warning:
Potential leak of memory pointed to by 'b'
[clang-analyzer-cplusplus.NewDeleteLeaks]

Bug: b/27101951
Test:Warning is gone.
Change-Id: If898bae71771f325c97777a19af0c0cf2e8a0400

libs/gui/tests/CpuConsumer_test.cpp

index 9c2e838..f1bf121 100644 (file)
@@ -33,6 +33,7 @@
 #include <utils/Mutex.h>
 #include <utils/Condition.h>
 
+#include <vector>
 #define CPU_CONSUMER_TEST_FORMAT_RAW 0
 #define CPU_CONSUMER_TEST_FORMAT_Y8 0
 #define CPU_CONSUMER_TEST_FORMAT_Y16 0
@@ -635,7 +636,7 @@ TEST_P(CpuConsumerTest, FromCpuLockMax) {
 
     // Consume
 
-    CpuConsumer::LockedBuffer *b = new CpuConsumer::LockedBuffer[params.maxLockedBuffers];
+    std::vector<CpuConsumer::LockedBuffer> b(params.maxLockedBuffers);
     for (int i = 0; i < params.maxLockedBuffers; i++) {
         ALOGV("Locking frame %d", i);
         err = mCC->lockNextBuffer(&b[i]);
@@ -684,9 +685,6 @@ TEST_P(CpuConsumerTest, FromCpuLockMax) {
     for (int i = 1; i < params.maxLockedBuffers; i++) {
         mCC->unlockBuffer(b[i]);
     }
-
-    delete[] b;
-
 }
 
 CpuConsumerTestParams y8TestSets[] = {