Code: void vp8_decoder_remove_threads(VP8D_COMP *pbi)
{
    /* shutdown MB Decoding thread; */
    if (pbi->b_multithreaded_rd)
    {
        int i;
 
        pbi->b_multithreaded_rd = 0;
        /* allow all threads to exit */
        for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
        {
            sem_post(&pbi->h_event_start_decoding[i]);
            pthread_join(pbi->h_decoding_thread[i], NULL);
        }
        for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
        {
            sem_destroy(&pbi->h_event_start_decoding[i]);
        }
        sem_destroy(&pbi->h_event_end_decoding);
            vpx_free(pbi->h_decoding_thread);
            pbi->h_decoding_thread = NULL;
            vpx_free(pbi->h_event_start_decoding);
            pbi->h_event_start_decoding = NULL;
            vpx_free(pbi->mb_row_di);
            pbi->mb_row_di = NULL ;
            vpx_free(pbi->de_thread_data);
            pbi->de_thread_data = NULL;
     }
 }

Vulnerability Type: DoS 
CWE ID: 
Summary: A denial of service vulnerability in libvpx in Mediaserver could enable a remote attacker to use a specially crafted file to cause a device hang or reboot. This issue is rated as High due to the possibility of remote denial of service. Product: Android. Versions: 4.4.4, 5.0.2, 5.1.1, 6.0, 6.0.1, 7.0, 7.1. Android ID: A-30436808.
Commit Message: vp8:fix threading issues

1 - stops de allocating before threads are closed.
2 - limits threads to mb_rows when mb_rows < partitions

BUG=webm:851
Bug: 30436808

Change-Id: Ie017818ed28103ca9d26d57087f31361b642e09b
(cherry picked from commit 70cca742efa20617c70c3209aa614a70f282f90e)
