surface ID initialization

When decoder ran into some corner case that the actual
buffer count is less than given buffer count, some buffers
are destoryed illegally.

Bug: 22299730
Change-Id: I13a383dfb7c2c03c950618317cb7afed64369b70
Signed-off-by: Tianmi Chen <tianmi.chen@intel.com>
diff --git a/videodecoder/VideoDecoderBase.cpp b/videodecoder/VideoDecoderBase.cpp
index 581b8ac..399bc6c 100644
--- a/videodecoder/VideoDecoderBase.cpp
+++ b/videodecoder/VideoDecoderBase.cpp
@@ -880,6 +880,9 @@
     mNumExtraSurfaces = numExtraSurface;
     mSurfaces = new VASurfaceID [mNumSurfaces + mNumExtraSurfaces];
     mExtraSurfaces = mSurfaces + mNumSurfaces;
+    for (int i = 0; i < mNumSurfaces + mNumExtraSurfaces; ++i) {
+        mSurfaces[i] = VA_INVALID_SURFACE;
+    }
     if (mSurfaces == NULL) {
         return DECODE_MEMORY_FAIL;
     }
@@ -1086,9 +1089,8 @@
         mSurfaceUserPtr = NULL;
     }
 
-    if (mSurfaces)
-    {
-        vaDestroySurfaces(mVADisplay, mSurfaces, mNumSurfaces + mNumExtraSurfaces);
+    if (mSurfaces) {
+        vaDestroySurfaces(mVADisplay, mSurfaces, mStoreMetaData ? mMetaDataBuffersNum : (mNumSurfaces + mNumExtraSurfaces));
         delete [] mSurfaces;
         mSurfaces = NULL;
     }