diff --git a/media/libvorbis/lib/vorbis_sharedbook.c b/media/libvorbis/lib/vorbis_sharedbook.c index 444f42b5aa..137486e540 100644 --- a/media/libvorbis/lib/vorbis_sharedbook.c +++ b/media/libvorbis/lib/vorbis_sharedbook.c @@ -352,9 +352,13 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ /* perform sort */ ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); - ogg_uint32_t **codep=alloca(sizeof(*codep)*n); + ogg_uint32_t **codep=_ogg_malloc(sizeof(*codep)*n); - if(codes==NULL)goto err_out; + if(codes==NULL || codep==NULL){ + if(codes)_ogg_free(codes); + if(codep)_ogg_free(codep); + goto err_out; + } for(i=0;icodelist=_ogg_malloc(n*sizeof(*c->codelist)); + if(c->codelist==NULL){ + _ogg_free(sortindex); + _ogg_free(codep); + _ogg_free(codes); + goto err_out; + } /* the index is a reverse index */ for(i=0;icodelist[sortindex[i]]=codes[i]; @@ -377,12 +393,20 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ c->valuelist=_book_unquantize(s,n,sortindex); c->dec_index=_ogg_malloc(n*sizeof(*c->dec_index)); + if(c->dec_index==NULL){ + _ogg_free(sortindex); + goto err_out; + } for(n=0,i=0;ientries;i++) if(s->lengthlist[i]>0) c->dec_index[sortindex[n++]]=i; c->dec_codelengths=_ogg_malloc(n*sizeof(*c->dec_codelengths)); + if(c->dec_codelengths==NULL){ + _ogg_free(sortindex); + goto err_out; + } c->dec_maxlength=0; for(n=0,i=0;ientries;i++) if(s->lengthlist[i]>0){ @@ -390,6 +414,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ if(s->lengthlist[i]>c->dec_maxlength) c->dec_maxlength=s->lengthlist[i]; } + _ogg_free(sortindex); if(n==1 && c->dec_maxlength==1){ /* special case the 'single entry codebook' with a single bit @@ -397,6 +422,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ unmodified decode paths. */ c->dec_firsttablen=1; c->dec_firsttable=_ogg_calloc(2,sizeof(*c->dec_firsttable)); + if(c->dec_firsttable==NULL)goto err_out; c->dec_firsttable[0]=c->dec_firsttable[1]=1; }else{ @@ -406,6 +432,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ tabn=1<dec_firsttablen; c->dec_firsttable=_ogg_calloc(tabn,sizeof(*c->dec_firsttable)); + if(c->dec_firsttable==NULL)goto err_out; for(i=0;idec_codelengths[i]<=c->dec_firsttablen){