shithub: opusfile

Download patch

ref: 6452e838e68e8f4fc0b3599523c760ac6276ce89
parent: a55c164e9891a9326188b7d4d216ec9a88373739
author: Felicia Lim <[email protected]>
date: Fri Jul 31 10:57:14 EDT 2020

Fix memory leak caused by incorrect link count to clean up on error.

--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -1267,6 +1267,8 @@
     ret=op_fetch_headers(_of,&links[nlinks].head,&links[nlinks].tags,
      _serialnos,_nserialnos,_cserialnos,last!=next?NULL:&og);
     if(OP_UNLIKELY(ret<0))return ret;
+    /*Mark the current link count so it can be cleaned up on error.*/
+    _of->nlinks=nlinks+1;
     links[nlinks].offset=next;
     links[nlinks].data_offset=_of->offset;
     links[nlinks].serialno=_of->os.serialno;
@@ -1277,8 +1279,7 @@
     if(OP_UNLIKELY(ret<0))return ret;
     links[nlinks].pcm_file_offset=total_duration;
     _searched=_of->offset;
-    /*Mark the current link count so it can be cleaned up on error.*/
-    _of->nlinks=++nlinks;
+    ++nlinks;
   }
   /*Last page is in the starting serialno list, so we've reached the last link.
     Now find the last granule position for it (if we didn't the first time we