Fix S_SMF_DATA.numStreams being non-zero while streams is uninitialized

Let S_SMF_DATA.numStreams set after S_SMF_DATA.streams is
initialized.

Bug: 23528803
Change-Id: Ie45156a03ec6700a9b0971626eb08cb5c9cdab6e
diff --git a/arm-wt-22k/lib_src/eas_smf.c b/arm-wt-22k/lib_src/eas_smf.c
index 7b0bdd8..8b54b8e 100644
--- a/arm-wt-22k/lib_src/eas_smf.c
+++ b/arm-wt-22k/lib_src/eas_smf.c
@@ -1049,11 +1049,16 @@
     EAS_RESULT result;
     EAS_I32 i;
     EAS_U16 division;
+    EAS_U16 numStreams;
     EAS_U32 chunkSize;
     EAS_U32 chunkStart;
     EAS_U32 temp;
     EAS_U32 ticks;
 
+    /* explicitly set numStreams to 0. It will later be used by SMF_Close to
+     * determine whether we have valid streams or not. */
+    pSMFData->numStreams = 0;
+
     /* rewind the file and find the end of the header chunk */
     if ((result = EAS_HWFileSeek(hwInstData, pSMFData->fileHandle, pSMFData->fileOffset + SMF_OFS_HEADER_SIZE)) != EAS_SUCCESS)
         goto ReadError;
@@ -1063,15 +1068,15 @@
     /* determine the number of tracks */
     if ((result = EAS_HWFileSeek(hwInstData, pSMFData->fileHandle, pSMFData->fileOffset + SMF_OFS_NUM_TRACKS)) != EAS_SUCCESS)
         goto ReadError;
-    if ((result = EAS_HWGetWord(hwInstData, pSMFData->fileHandle, &pSMFData->numStreams, EAS_TRUE)) != EAS_SUCCESS)
+    if ((result = EAS_HWGetWord(hwInstData, pSMFData->fileHandle, &numStreams, EAS_TRUE)) != EAS_SUCCESS)
         goto ReadError;
 
     /* limit the number of tracks */
-    if (pSMFData->numStreams > MAX_SMF_STREAMS)
+    if (numStreams > MAX_SMF_STREAMS)
     {
-        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "SMF file contains %u tracks, playing %d tracks\n", pSMFData->numStreams, MAX_SMF_STREAMS); */ }
-        pSMFData->numStreams = MAX_SMF_STREAMS;
-    } else if (pSMFData->numStreams == 0)
+        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "SMF file contains %u tracks, playing %d tracks\n", numStreams, MAX_SMF_STREAMS); */ }
+        numStreams = MAX_SMF_STREAMS;
+    } else if (numStreams == 0)
     {
         /* avoid 0 sized allocation */
         return EAS_ERROR_PARAMETER_RANGE;
@@ -1092,13 +1097,14 @@
     /* dynamic memory allocation, allocate memory for streams */
     if (pSMFData->streams == NULL)
     {
-        pSMFData->streams = EAS_HWMalloc(hwInstData,sizeof(S_SMF_STREAM) * pSMFData->numStreams);
+        pSMFData->streams = EAS_HWMalloc(hwInstData,sizeof(S_SMF_STREAM) * numStreams);
         if (pSMFData->streams == NULL)
             return EAS_ERROR_MALLOC_FAILED;
 
         /* zero the memory to insure complete initialization */
-        EAS_HWMemSet((void *)(pSMFData->streams), 0, sizeof(S_SMF_STREAM) * pSMFData->numStreams);
+        EAS_HWMemSet((void *)(pSMFData->streams), 0, sizeof(S_SMF_STREAM) * numStreams);
     }
+    pSMFData->numStreams = numStreams;
 
     /* find the start of each track */
     chunkStart = (EAS_U32) pSMFData->fileOffset;